googleapis / google-api-python-client

🐍 The official Python client library for Google's discovery based APIs.
https://googleapis.github.io/google-api-python-client/docs/
Apache License 2.0
7.82k stars 2.42k forks source link

Google Play Developer Reporting API . vitals . errors . counts #1761

Open newFunL opened 2 years ago

newFunL commented 2 years ago

Environment details

Code example

body = {
   "metrics": ["distinctUsers"],
   "timelineSpec":{
           "aggregationPeriod": "DAILY",
           "startTime": {
                   'timeZone': {'id': 'America/Los_Angeles'},
                   'year': 2022,
                   'month': 4,
                   'day': 4
           },
           "endTime": {
                   'timeZone': {'id': 'America/Los_Angeles'},
                   'year': 2022,
                   'month': 4,
                   'day': 11
           }
   }
}
count_msg = sqladmin.vitals().errors().counts().query(
        name="apps/{com.example.app}/errorCountMetricSet",
        body=body
).execute()

Stack trace

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://playdeveloperreporting.googleapis.com/v1alpha1/apps/com.kwai.video/errorCountMetricSet:query?alt=json returned "The requested metrics, dimensions and aggregation_period cannot be used together.". Details: "The requested metrics, dimensions and aggregation_period cannot be used together.">

I have completely referred to the corresponding API documents to fill in https://googleapis.github.io/google-api-python-client/docs/dyn/playdeveloperreporting_v1alpha1.vitals.errors.counts.html#query My question is:

Are there any errors in my parameters and how to correct them

Thanks!

parthea commented 2 years ago

Hi @newFunL,

Please could you try out a similar request in the 'Try this API' interface on this page and check whether the issue still exists? This helps to confirm if this is a client library issue or an API issue. If it is an API issue, I'll reach out to the API team for more information. Regarding the timezone, can you confirm that you're using America/Los_Angeles as the docs mention The default and only supported timezone is America/Los_Angeles.

Regarding the error The requested metrics, dimensions and aggregation_period cannot be used together., what I've gathered so far is that this translates to no matching configuration. Please let me know if you have any luck with the Try this API page. The page may help to determine which parameters are causing the issue.

newFunL commented 2 years ago

Thank you for your reply I used the correct time zone selection. I try to request in this way

credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE,scopes=SCOPES)
request = google.auth.transport.requests.Request()
credentials.refresh(request)
token = credentials.token
headers = {"Authorization": 'Bearer ' + token}
url = "https://playdeveloperreporting.googleapis.com/v1alpha1/apps/{com.example.app}/errorCountMetricSet:query"
body = {
   "metrics": ["distinctUsers"],
   "dimensions": ["versionCode"],
   "timelineSpec":{
           "aggregationPeriod": "DAILY",
           "startTime": {
                   'timeZone': {'id': 'America/Los_Angeles'},
                   'year': 2022,
                   'month': 4,
                   'day': 4
           },
           "endTime": {
                   'timeZone': {'id': 'America/Los_Angeles'},
                   'year': 2022,
                   'month': 4,
                   'day': 5
           }
   }
}
result_msg = requests.post(url=url,json=body,headers=headers).text

This error still exists,I think it seems that there is a problem with the corresponding API, please check it out

Stack trace

{
  "error": {
    "code": 400,
    "message": "The requested metrics, dimensions and aggregation_period cannot be used together.",
    "status": "INVALID_ARGUMENT"
  }
}
parthea commented 2 years ago

Hi @newFunL, thanks for confirming the time zone used. I've created an internal issue for the API team. Googlers see b/229362343

galbgonz commented 2 years ago

Hi @newFunL, thanks for the bug report. The queries to errorCountMetricSet must specify the "errorType" dimension in the request, it is a required dimension. I have looked at the API docs and we missed documenting this. Sorry! I will get the API docs fixed asap.

azadgandomi commented 2 years ago

I can confirm that adding reportType to dimensions fix the issue.

newFunL commented 2 years ago

Thanks for reply. I can add reportType to dimensions fix the issue.

trinath89 commented 2 years ago

Hi ,apologies for the off topic or irrelevant question, I am trying to pull the Method: vitals.crashrate.get using the Postman framing my get request as GET https://playdeveloperreporting.googleapis.com/v1beta1/{name=apps/*/crashRateMetricSet} the required OAUTH scope given in the reference document is https://www.googleapis.com/auth/playdeveloperreporting

I could not find this scope in the https://developers.google.com/identity/protocols/oauth2/scopes

I am now lost as i am not sure which scope to be used. Please help me

galbgonz commented 2 years ago

Hi @trinath89,

the API right now only supports access with GCP service accounts, which don't use scopes (scopes are only used with human accounts). Could you send me a link to the documentation where it talks about OAuth scopes? I will have it fixed.

If you have a strong need for human account access in the API, could you let me know what is the use case? It will be useful when it comes to prioritising new features.

Thanks

trinath89 commented 2 years ago

Hi @galbgonz,

Thanks a lot for the reply, I have never worked with API's before, so i was not sure how to get the data for crashRateMetricSet.

Previously: I followed this guide https://developers.google.com/android-publisher/authorization which did not asked me to create the service accounts and was only using OAUTH to generate the bearer token and access token and was able to retrieve the reviews via Postman. so I misinterpreted that I can follow the same process to retrieve the data for crashRateMetricSet.

Understood from your comment that, i need to create the service account with proper permissions.

any guide explaining the process to get the data for the below metric using the service account via postman will be greatly helpful to me. https://developers.google.com/play/developer/reporting/reference/rest/v1alpha1/vitals.crashrate/get

Please refer to the Authorization Scopes section in the above mentioned link that probably needs to be corrected .

Thankyou once again.

galbgonz commented 1 year ago

Hi @trinath89,

thanks for the details. I have confirmed that the scope is actually still needed to generate a bearer token even when using service accounts.

The way to use a service account is roughly as follows:

  1. Create a GCP consumer project and get an API key for it
  2. Link your GCP consumer project to the Play Console developer account in the API access UI
  3. Create a service account (https://cloud.google.com/iam/docs/service-accounts), and download the account's key file (the equivalent of its password)
  4. "Invite" that service account to be a user of your Play Console developer, and grant at least "read only" access to some or all apps.
  5. Exchange the service account key for an OAuth token using a tool such as oauth2l.

I assume you have done (1), and (2) since you were able to fetch reviews. If in step 3 you downloaded the key into a file named key.json, you can then use this command to get a bearer token:

$ oauth2l fetch --json ~/key.json --scope playdeveloperreporting

As I said the API OAuth scope currently is only enabled to work with service accounts. We're planning to allow person OAuth tokens too but the timeline is unclear at the moment.