Python - how to authenticate consult Google Analyt

2019-07-28 05:44发布

I have a python script to consult certain data from Google Analytics but im trying to go a little bit further and let Lambda (from amazon web services) do it automatically for me everyday. But i encounter a problem and im stuck with it.

I don't know how can i authenticate OAuth 2.0 from the script without using a client_secrets.json file and if there is no other way to do it how and where i should leave the .json file in order to let it authenticate itself.

As it explains here since im not using one of google services i need to use:

from oauth2client.service_account import ServiceAccountCredentials

scopes = ['https://www.googleapis.com/auth/sqlservice.admin']

credentials = ServiceAccountCredentials.from_json_keyfile_name(
'/path/to/keyfile.json', scopes)

but i have no path for the file.

1条回答
相关推荐>>
2楼-- · 2019-07-28 05:50

If you check out the docs for ServiceAccountCredentials at https://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html#oauth2client.service_account.ServiceAccountCredentials

you'll see that as well as .from_json_keyfile_name there is a constructor from_json(json_data). That should do what you need.

查看更多
登录 后发表回答