Truy vấn các nhóm chỉ số
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sau khi thiết lập mọi thứ, bạn có thể gửi yêu cầu đến API Google Play Developer Reporting để truy xuất siêu dữ liệu về các nhóm chỉ số và truy vấn chỉ số của chúng.
Các mẫu mã sau đây minh hoạ cách gửi một số yêu cầu đơn giản. Ví dụ: các phương thức bên dưới cho biết cách truy xuất nhiều chỉ số cho ứng dụng của bạn. Có một số tham số truy vấn khác nhau mà bạn có thể dùng để thu hẹp truy vấn.
Ví dụ sau đây truy xuất siêu dữ liệu cho tập hợp chỉ số tỷ lệ gặp sự cố được đặt cho một ứng dụng hư cấu, com.example.app
.
Yêu cầu đơn giản:
Yêu cầu HTTP GET
này chỉ định tham số tên ứng dụng và trả về tài nguyên chỉ số đầy đủ được liên kết với ứng dụng của bạn.
GET https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/crashRateMetricSet
Phản hồi thông tin về chỉ số:
Phản hồi này bao gồm các trường sau liên quan đến nhóm chỉ số:
{
"freshness_info": {
"freshness": [
"aggregation_period": "DAILY"
"latest_end_time": { year: "2021" month: "7" day: "22" time_zone: "America/Los_Angeles" }
]
}
}
Sử dụng tính năng truy vấn
Yêu cầu HTTP POST
sau đây cho cùng một tài nguyên này sử dụng điểm cuối query
để truy xuất dữ liệu cụ thể trong tập hợp chỉ số.
POST https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/crashRateMetricSet:query
Trong nội dung yêu cầu, hãy truyền các lựa chọn truy vấn để truy xuất chỉ số dựa trên các tiêu chí cụ thể.
{
"timeline_spec": {
"aggregation_period": "DAILY"
"start_time": { year: "2021" month: "7" day: "1" time_zone: "America/Los_Angeles" }
"end_time": { year: "2021" month: "7" day: "3" time_zone: "America/Los_Angeles" }
}
"dimensions": ["apiLevel"]
"metrics": ["errorReportCount", "distinctUsers"]
"page_size": "10"
}
Dưới đây là một số ví dụ ở cấp bộ sưu tập:
Trường |
timelineSpec |
object (TimelineSpec )
Quy cách của các thông số tổng hợp dòng thời gian. Vui lòng kiểm tra tài liệu của từng bộ chỉ số để biết danh sách các khoảng thời gian tổng hợp được hỗ trợ.
|
dimensions[] |
string
Các phương diện để phân chia chỉ số. Vui lòng kiểm tra tài liệu của từng bộ chỉ số để biết danh sách các phương diện được hỗ trợ.
|
metrics[] |
string
Các chỉ số cần tổng hợp.
|
pageSize |
integer
Kích thước tối đa của dữ liệu được trả về. Nếu không chỉ định, tối đa 1.000 hàng sẽ được trả về. Giá trị tối đa là 100.000; các giá trị lớn hơn 100.000 sẽ được chuyển đổi thành 100.000.
|
Xử lý phản hồi
Sau khi xử lý một yêu cầu hợp lệ có chứa các trường hợp lệ, máy chủ sẽ gửi lại mã trạng thái HTTP 200 OK
cùng với dữ liệu được yêu cầu. Nếu tham số truy vấn fields
có lỗi hoặc không hợp lệ, thì máy chủ sẽ trả về mã trạng thái HTTP 400 Bad Request
, cùng với một thông báo lỗi cho người dùng biết điều gì không ổn với lựa chọn trường của họ (ví dụ: "Invalid field timeline_spec"
).
Sau đây là ví dụ về phản hồi được minh hoạ trong phần giới thiệu ở trên.
POST https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/crashRateMetricSet:query
Phản hồi sẽ có dạng như sau:
200 OK
{
rows: [
{
aggregation_period: "DAILY"
start_time: { year: "2021" month: "7" day: "1" time_zone: "America/Los_Angeles" }
dimensions: [{dimension: "apiLevel" int64_value: "20"}]
metrics: [
{metric: "errorReportCount" decimal_value: "100"},
{metric: "distinctUsers" decimal_value: "57"},
]
}, {
aggregation_period: "DAILY"
start_time: { year: "2021" month: "7" day: "1" time_zone: "America/Los_Angeles" }
dimensions: [{dimension: "apiLevel" int64_value: "21"}]
metrics: [
{metric: "errorReportCount" decimal_value: "123"},
{metric: "distinctUsers" decimal_value: "65"},
]
},
...
]
next_page_token: "eW91IGhhdmUgdG9vIG11Y2ggZnJlZSB0aW1l"
}
Lưu ý: Đối với những API hỗ trợ các tham số truy vấn để phân trang dữ liệu (ví dụ: maxResults
và nextPageToken
), hãy sử dụng các tham số đó để giảm kết quả của mỗi truy vấn xuống một kích thước có thể quản lý.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eSend requests to the Google Play Developer Reporting API to retrieve app metric data after setup.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003equery\u003c/code\u003e endpoint with parameters like \u003ccode\u003etimeline_spec\u003c/code\u003e, \u003ccode\u003edimensions\u003c/code\u003e, and \u003ccode\u003emetrics\u003c/code\u003e to retrieve specific data within a metric set.\u003c/p\u003e\n"],["\u003cp\u003eResponses include metric data based on the query, or error messages for invalid requests.\u003c/p\u003e\n"],["\u003cp\u003eFor large datasets, utilize pagination parameters like \u003ccode\u003epageSize\u003c/code\u003e to handle responses efficiently.\u003c/p\u003e\n"]]],["After setup, you can interact with the Google Play Developer Reporting API. A `GET` request, like for `com.example.app`, can retrieve metric set metadata, including freshness information. To query specific data, use a `POST` request with parameters like `timeline_spec`, `dimensions`, `metrics`, and `page_size`. A successful request returns a `200 OK` status and the requested data, while a `400 Bad Request` signifies errors in the query parameters. Use pagination to manage large data sets.\n"],null,["# Querying Metric Sets\n\nAfter you've set everything up, you can send requests to the Google Play Developer Reporting API to retrieve\nmetadata about metric sets and query their metrics.\n\n\nThe following code samples demonstrate how to send a few simple requests. For example, the\nmethods below show you how to retrieve various metrics for your app. There are a few different\nquery parameters that can be used to narrow your query.\n\nRetrieving metric set metadata\n------------------------------\n\n\nThe following example retrieves the metadata for the crash rate metric set for a fictional\napplication, `com.example.app`.\n\n#### Simple request:\n\n\nThis HTTP `GET` request specifies the application name parameter and returns the\nfull metric resource associated with your application. \n\n```text\nGET https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/crashRateMetricSet\n```\n\n#### Metric info response:\n\n\nThe response includes the following fields related to the metric set: \n\n```verilog\n{\n \"freshness_info\": {\n \"freshness\": [\n \"aggregation_period\": \"DAILY\"\n \"latest_end_time\": { year: \"2021\" month: \"7\" day: \"22\" time_zone: \"America/Los_Angeles\" }\n ]\n }\n}\n```\n\nUsing the query feature\n-----------------------\n\n\nThe following HTTP `POST`request for this same resource uses the `query`\nendpoint to retrieve specific data from within the metric set. \n\n```text\nPOST https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/crashRateMetricSet:query\n```\n\n\nIn the request body, pass query options to retrieve metrics based on specific criteria. \n\n```verilog\n{\n \"timeline_spec\": {\n \"aggregation_period\": \"DAILY\"\n \"start_time\": { year: \"2021\" month: \"7\" day: \"1\" time_zone: \"America/Los_Angeles\" }\n \"end_time\": { year: \"2021\" month: \"7\" day: \"3\" time_zone: \"America/Los_Angeles\" }\n }\n \"dimensions\": [\"apiLevel\"]\n \"metrics\": [\"errorReportCount\", \"distinctUsers\"]\n \"page_size\": \"10\"\n}\n```\n\n\nHere are some collection-level examples:\n\n| Fields ||\n|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `timelineSpec` | `object (`[TimelineSpec](/play/developer/reporting/reference/rest/v1beta1/anomalies#TimelineSpec)`)` Specification of the timeline aggregation parameters. Please check the documentation of each metric set for a list of what aggregation periods are supported. |\n| `dimensions[]` | `string` Dimensions to slice the metrics by. Please check the documentation of each metric set for a list of what dimensions are supported. |\n| `metrics[]` | `string` Metrics to aggregate. |\n| `pageSize` | `integer` Maximum size of the returned data. If unspecified, at most 1000 rows will be returned. The maximum value is 100,000; values above 100,000 will be coerced to 100,000. |\n\n### Handling responses\n\n\nAfter a server processes a valid request that includes valid fields, it sends back an HTTP\n`200 OK` status code, along with the requested data. If the `fields`\nquery parameter has an error or is otherwise invalid, the server returns an HTTP\n`400 Bad Request` status code, along with an error message telling the user what\nwas wrong with their fields selection (for example, `\"Invalid field timeline_spec\"`).\n\n\nHere is the response example shown in the introductory section above. \n\n```text\nPOST https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/crashRateMetricSet:query\n```\n\nThe response looks like this: \n\n```\n200 OK\n``` \n\n```verilog\n{\n rows: [\n {\n aggregation_period: \"DAILY\"\n start_time: { year: \"2021\" month: \"7\" day: \"1\" time_zone: \"America/Los_Angeles\" }\n dimensions: [{dimension: \"apiLevel\" int64_value: \"20\"}]\n metrics: [\n {metric: \"errorReportCount\" decimal_value: \"100\"},\n {metric: \"distinctUsers\" decimal_value: \"57\"},\n ]\n }, {\n aggregation_period: \"DAILY\"\n start_time: { year: \"2021\" month: \"7\" day: \"1\" time_zone: \"America/Los_Angeles\" }\n dimensions: [{dimension: \"apiLevel\" int64_value: \"21\"}]\n metrics: [\n {metric: \"errorReportCount\" decimal_value: \"123\"},\n {metric: \"distinctUsers\" decimal_value: \"65\"},\n ]\n },\n ...\n ]\n next_page_token: \"eW91IGhhdmUgdG9vIG11Y2ggZnJlZSB0aW1l\"\n}\n```\n\n\n**Note:** For APIs that support query parameters for data pagination (`maxResults`\nand `nextPageToken`, for example), use those parameters to reduce the results of each\nquery to a manageable size."]]