Python - how to authenticate consult Google Analytics from AWS Lambda?

那年仲夏 提交于 2019-12-13 17:19:55

问题


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:


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.



来源:https://stackoverflow.com/questions/44975002/python-how-to-authenticate-consult-google-analytics-from-aws-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!