简体   繁体   中英

Can't connect to Google playdeveloperreporting API

I'm trying to use Google Play Developer Reporting API v1beta1 for import Android Vitals statistics. For it I'm using service_account created by system administrator. But when script send query for load data it falls with error of linking Google Cloud with Play Console, But admin said that account linked with Google Play. I searched in Google but couldn't find same problem. Please help!

Script:

from google.oauth2 import service_account
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials

SCOPES = ["https://www.googleapis.com/auth/playdeveloperreporting"]
    credentials = service_account.Credentials.from_service_account_file('servise_account.json')
    scoped_credentials = credentials.with_scopes(SCOPES)
    reporting_user = build("playdeveloperreporting", "v1beta1", credentials=scoped_credentials, cache_discovery=False)
    
    body = {"dimensions": ["versionCode"],
            "metrics": ["anrRate", "anrRate7dUserWeighted", "distinctUsers"],
            "timelineSpec": {"aggregationPeriod": "DAILY",
                             "endTime": {
                               "day": 16,
                               "month": 5,
                               "year": 2022
                             },
                             "startTime": {
                               "day": 10,
                               "month": 5,
                               "year": 2022
                             }}}
    
    d = reporting_user.vitals().crashrate().query(name="apps/com.example.game/crashRateMetricSet", body=body).execute()
    pprint(d)

Error text:

Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1112, in _run_raw_task
    self._prepare_and_execute_task_with_callbacks(context, task)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1285, in _prepare_and_execute_task_with_callbacks
    result = self._execute_task(context, task_copy)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1315, in _execute_task
    result = task_copy.execute(context=context)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/operators/python.py", line 117, in execute
    return_value = self.execute_callable()
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/operators/python.py", line 128, in execute_callable
    return self.python_callable(*self.op_args, **self.op_kwargs)
  File "/opt/airflow/dags/anr_crash_share.py", line 89, in query
    d = reporting_user.vitals().crashrate().query(name="apps/com.example.game/crashRateMetricSet", body=body).execute()
  File "/home/airflow/.local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/googleapiclient/http.py", line 915, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.game/crashRateMetricSet?alt=json returned "The linked Google Cloud project does not match the project used to call this API. Requests to the Google Play Developer Reporting API must use a service account or authenticate through an OAuth client belonging to the linked Cloud project.". Details: "The linked Google Cloud project does not match the project used to call this API. Requests to the Google Play Developer Reporting API must use a service account or authenticate through an OAuth client belonging to the linked Cloud project.">

Looks like the service account you are calling with is not created in the project that is linked to the Google Play account. Open the 'servise_account.json' file that I see in your file. Check the project id json field in there. It should match the project in the Google Play.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM