Method: projects.getMetrics
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
รับข้อมูลเมตริกสำหรับสคริปต์ เช่น จำนวนการดำเนินการและผู้ใช้ที่ใช้งานอยู่
คำขอ HTTP
GET https://script.googleapis.com/v1/projects/{scriptId}/metrics
URL ใช้ไวยากรณ์การแปลง gRPC
พารามิเตอร์เส้นทาง
พารามิเตอร์ |
scriptId |
string
ช่องที่ต้องกรอกซึ่งระบุสคริปต์เพื่อรับเมตริก
|
พารามิเตอร์การค้นหา
พารามิเตอร์ |
metricsGranularity |
enum (MetricsGranularity )
ช่องที่ต้องกรอกซึ่งระบุรายละเอียดของเมตริกที่แสดงขึ้น
|
metricsFilter |
object (MetricsFilter )
ช่องที่ไม่บังคับซึ่งมีตัวกรองที่จะใช้กับคำขอ ซึ่งจะจำกัดขอบเขตของเมตริกที่ส่งคืนกลับไปยังเมตริกที่ระบุไว้ในตัวกรอง
|
เนื้อหาของคำขอ
เนื้อหาของคำขอต้องว่างเปล่า
เนื้อหาการตอบกลับ
หากทำสำเร็จ เนื้อหาการตอบกลับจะมีข้อมูลซึ่งมีโครงสร้างดังต่อไปนี้
ทรัพยากรที่มีสถิติการใช้งานสำหรับสคริปต์ที่ระบุ โดยอิงตามตัวกรองและมาสก์ที่ให้ไว้ซึ่งอยู่ในคำขอ
ช่อง |
activeUsers[] |
object (MetricsValue )
จำนวนผู้ใช้ที่ใช้งานอยู่
|
totalExecutions[] |
object (MetricsValue )
จำนวนการดำเนินการทั้งหมด
|
failedExecutions[] |
object (MetricsValue )
จำนวนการดำเนินการที่ไม่สำเร็จ
|
ขอบเขตการให้สิทธิ์
ต้องใช้ขอบเขต OAuth ต่อไปนี้
https://www.googleapis.com/auth/script.metrics
สำหรับข้อมูลเพิ่มเติม โปรดดูที่ภาพรวมของ OAuth 2.0
MetricsGranularity
รายละเอียดของเมตริกที่จะแสดงข้อมูล
Enum |
UNSPECIFIED_GRANULARITY |
รายละเอียดเมตริกเริ่มต้นที่ใช้ในการค้นหาไม่มีเมตริก |
WEEKLY |
แสดงเมตริกรายสัปดาห์ |
DAILY |
แสดงเมตริกรายวันในระยะเวลา 7 วัน |
MetricsFilter
ตัวกรองที่ใช้เพื่อลดขอบเขตของคำขอ
การแสดง JSON |
{
"deploymentId": string
} |
ช่อง |
deploymentId |
string
ช่องที่ไม่บังคับระบุการติดตั้งใช้งานที่เฉพาะเจาะจงเพื่อเรียกข้อมูลเมตริก
|
MetricsValue
ค่าเมตริกที่เก็บจำนวนการดำเนินการที่นับ
การแสดง JSON |
{
"value": string,
"startTime": string,
"endTime": string
} |
ช่อง |
value |
string
ระบุจำนวนการดำเนินการที่นับ
|
startTime |
string (Timestamp format)
ช่องที่ต้องกรอกซึ่งระบุเวลาเริ่มต้นของช่วง การประทับเวลาเป็น RFC3339 UTC "Zulu" โดยมีความละเอียดระดับนาโนวินาทีและมีเลขเศษส่วนสูงสุด 9 หลัก ตัวอย่าง: "2014-10-02T15:01:23Z" และ "2014-10-02T15:01:23.045123456Z"
|
endTime |
string (Timestamp format)
ช่องที่ต้องกรอกซึ่งระบุเวลาสิ้นสุดของช่วง การประทับเวลาเป็น RFC3339 UTC "Zulu" โดยมีความละเอียดระดับนาโนวินาทีและมีเลขเศษส่วนสูงสุด 9 หลัก ตัวอย่าง: "2014-10-02T15:01:23Z" และ "2014-10-02T15:01:23.045123456Z"
|
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eRetrieve usage statistics for Apps Script projects, including active users, total executions, and failed executions.\u003c/p\u003e\n"],["\u003cp\u003eFilter metrics by granularity (daily, weekly) and specific deployments.\u003c/p\u003e\n"],["\u003cp\u003eRequires authorization with the \u003ccode\u003ehttps://www.googleapis.com/auth/script.metrics\u003c/code\u003e scope.\u003c/p\u003e\n"],["\u003cp\u003eThe API uses a \u003ccode\u003eGET\u003c/code\u003e request with path and query parameters to specify the script and desired metrics.\u003c/p\u003e\n"],["\u003cp\u003eResponse data includes metric values with start and end times for the specified intervals.\u003c/p\u003e\n"]]],[],null,["# Method: projects.getMetrics\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Path parameters](#body.PATH_PARAMETERS)\n- [Query parameters](#body.QUERY_PARAMETERS)\n- [Request body](#body.request_body)\n- [Response body](#body.response_body)\n - [JSON representation](#body.Metrics.SCHEMA_REPRESENTATION)\n- [Authorization Scopes](#body.aspect)\n- [MetricsGranularity](#MetricsGranularity)\n- [MetricsFilter](#MetricsFilter)\n - [JSON representation](#MetricsFilter.SCHEMA_REPRESENTATION)\n- [MetricsValue](#MetricsValue)\n - [JSON representation](#MetricsValue.SCHEMA_REPRESENTATION)\n- [Try it!](#try-it)\n\nGet metrics data for scripts, such as number of executions and active users.\n\n### HTTP request\n\n`GET https://script.googleapis.com/v1/projects/{scriptId}/metrics`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Path parameters\n\n| Parameters ||\n|------------|-------------------------------------------------------------------|\n| `scriptId` | `string` Required field indicating the script to get metrics for. |\n\n### Query parameters\n\n| Parameters ||\n|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `metricsGranularity` | `enum (`[MetricsGranularity](/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsGranularity)`)` Required field indicating what granularity of metrics are returned. |\n| `metricsFilter` | `object (`[MetricsFilter](/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsFilter)`)` Optional field containing filters to apply to the request. This limits the scope of the metrics returned to those specified in the filter. |\n\n### Request body\n\nThe request body must be empty.\n\n### Response body\n\nIf successful, the response body contains data with the following structure:\nResource containing usage stats for a given script, based on the supplied filter and mask present in the request.\n\n| JSON representation |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"activeUsers\": [ { object (/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsValue) } ], \"totalExecutions\": [ { object (/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsValue) } ], \"failedExecutions\": [ { object (/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsValue) } ] } ``` |\n\n| Fields ||\n|----------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| `activeUsers[]` | `object (`[MetricsValue](/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsValue)`)` Number of active users. |\n| `totalExecutions[]` | `object (`[MetricsValue](/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsValue)`)` Number of total executions. |\n| `failedExecutions[]` | `object (`[MetricsValue](/apps-script/api/reference/rest/v1/projects/getMetrics#MetricsValue)`)` Number of failed executions. |\n\n### Authorization Scopes\n\nRequires the following OAuth scope:\n\n- `https://www.googleapis.com/auth/script.metrics`\n\nFor more information, see the [OAuth 2.0 Overview](https://developers.google.com/identity/protocols/OAuth2).\n\nMetricsGranularity\n------------------\n\nThe granularity of metric to return data for.\n\n| Enums ||\n|---------------------------|------------------------------------------------------|\n| `UNSPECIFIED_GRANULARITY` | Default metric granularity used to query no metrics. |\n| `WEEKLY` | Represents weekly metrics. |\n| `DAILY` | Represents daily metrics over a period of 7 days. |\n\nMetricsFilter\n-------------\n\nFilter used to reduce the scope of the request.\n\n| JSON representation |\n|------------------------------------|\n| ``` { \"deploymentId\": string } ``` |\n\n| Fields ||\n|----------------|------------------------------------------------------------------------------------|\n| `deploymentId` | `string` Optional field indicating a specific deployment to retrieve metrics from. |\n\nMetricsValue\n------------\n\nMetrics value that holds number of executions counted.\n\n| JSON representation |\n|---------------------------------------------------------------------|\n| ``` { \"value\": string, \"startTime\": string, \"endTime\": string } ``` |\n\n| Fields ||\n|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `value` | `string` Indicates the number of executions counted. |\n| `startTime` | `string (`[Timestamp](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp)` format)` Required field indicating the start time of the interval. A timestamp in RFC3339 UTC \"Zulu\" format, with nanosecond resolution and up to nine fractional digits. Examples: `\"2014-10-02T15:01:23Z\"` and `\"2014-10-02T15:01:23.045123456Z\"`. |\n| `endTime` | `string (`[Timestamp](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp)` format)` Required field indicating the end time of the interval. A timestamp in RFC3339 UTC \"Zulu\" format, with nanosecond resolution and up to nine fractional digits. Examples: `\"2014-10-02T15:01:23Z\"` and `\"2014-10-02T15:01:23.045123456Z\"`. |"]]