python - Check if a Google API is enabled -
the following part of script creates 2 resources google analytics api versions 3 , 4.
from oauth2client.service_account import serviceaccountcredentials apiclient.discovery import build scopes = ['https://www.googleapis.com/auth/analytics.readonly'] client_secret_file = some_path credentials = serviceaccountcredentials.from_json_keyfile_name(client_secret_file, scopes=scopes) analytics_resource_v3 = build('analytics', 'v3', credentials=credentials) analytics_resource_v4 = build('analytics', 'v4', credentials=credentials)
prior running query these resources, access apis should enabled. if not, query return googleapiclient.errors.httperror: <httperror 403 when requesting ... access not configured. ... if enabled api recently, wait few minutes action propagate our systems , retry.
my issue following. there way check api enabled? did not find method of class resource
common apis.
for example, 1 can run analytics_resource_v3.management().accounts().list().execute()
, analytics_resource_v4.reports().batchget(body={'reportrequests':[...]}).execute()
, catch errors have liked uniform way, independent of api (as scripts run drive, sheets, etc).
thanks help.
Comments
Post a Comment