def get_access_token(ga_key_filepath):
# from https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/
# Defines a method to get an access token from the credentials object.
# The access token is automatically refreshed if it has expired.
# The scope for the OAuth2 request.
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'
# Construct a credentials objects from the key data and OAuth2 scope.
_credentials = ServiceAccountCredentials.from_json_keyfile_name(
ga_key_filepath, SCOPE)
return _credentials.get_access_token().access_token
评论列表
文章目录