I'm using google python libraty to request ANR data for my app, script is very simple
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
# The CLIENT_SECRETS_FILE variable specifies the name of a file that contains
# the OAuth 2.0 information for this application, including its client_id and
# client_secret.
CLIENT_SECRETS_FILE = "client_secret.json"
# This access scope grants read-only access to the authenticated user's apps
SCOPES = ['https://www.googleapis.com/auth/androidpublisher']
API_SERVICE_NAME = 'playdeveloperreporting'
API_VERSION = 'v1beta1'
ANR_METHOD_NAME = 'apps/com.my.app/anrRateMetricSet'
flow = InstalledAppFlow.from_client_secrets_file(
CLIENT_SECRETS_FILE,
scopes=SCOPES)
def get_authenticated_service():
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_local_server(host='localhost',
port=5000,
authorization_prompt_message='Please visit this URL: {url}',
success_message='The auth flow is complete; you may close this window.',
open_browser=True)
return build(API_SERVICE_NAME, API_VERSION, credentials=credentials)
def getAnrReport():
report_service = get_authenticated_service()
vitals = report_service.vitals()
anr = vitals.anrrate()
userPerceivedAnrRate7dUserWeighted = anr.get(name=ANR_METHOD_NAME, x__xgafv='2').execute()
report_service.close()
# ...
if __name__ == '__main__':
getAnrReport()
But for some reason I get an error
googleapiclient.errors.HttpError:
HttpError 403 when requesting https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.my.app/anrRateMetricSet?%24.xgafv=2&alt=json
returned "Request had insufficient authentication scopes.".
Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', 'domain': 'googleapis.com', 'metadata': {'method': 'google.play.developer.reporting.v1beta1.VitalsService.GetAnrRateMetricSet', 'service': 'playdeveloperreporting.googleapis.com'}}]"
Documentation https://developers.google.com/play/developer/reporting/reference/rest/v1beta1/vitals.anrrate/get says
Authorization Scopes Requires the following OAuth scope:
Higher level documentation https://developers.google.com/play/developer/reporting/reference/rest/v1beta1/vitals.anrrate says
Required permissions: to access this resource, the calling user needs the View app information (read-only) permission for the app.
I do have that permission and my google user can access app info and ANR rate in Google Play Console. I'm also requesting playdeveloperreporting
scope as per documentation, but the scope is insufficient for some reason, what am I doing wrong?
Note: scope in my script is https://www.googleapis.com/auth/androidpublisher
Documentation says it should be https://www.googleapis.com/auth/playdeveloperreporting but such scope cannot be requested due to error:
Some requested scopes cannot be shown: [https://www.googleapis.com/auth/playdeveloperreporting]
Error 400: invalid_scope