google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

Google Play Developer Reporting API . vitals . errors . counts

Open newFunL opened this issue 3 years ago • 10 comments

Environment details

  • OS type and version:
  • Python version: 3.6.8
  • pip version: 21.2.3
  • google-api-python-client version: 2.44.0

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!

newFunL avatar Apr 13 '22 13:04 newFunL

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.

parthea avatar Apr 14 '22 22:04 parthea

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"
  }
}

newFunL avatar Apr 15 '22 11:04 newFunL

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

parthea avatar Apr 15 '22 11:04 parthea

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.

arubegonsan avatar Apr 26 '22 12:04 arubegonsan

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

azadgandomi avatar Apr 26 '22 13:04 azadgandomi

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

newFunL avatar Apr 28 '22 03:04 newFunL

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

trinath89 avatar Nov 22 '22 07:11 trinath89

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

arubegonsan avatar Nov 22 '22 10:11 arubegonsan

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.

trinath89 avatar Nov 23 '22 08:11 trinath89

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.

arubegonsan avatar Dec 02 '22 14:12 arubegonsan