Python - 如何验证从AWS Lambda咨询Google Analytics? [英] Python - how to authenticate consult Google Analytics from AWS Lambda?

查看:167
本文介绍了Python - 如何验证从AWS Lambda咨询Google Analytics?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本来咨询谷歌分析的某些数据,但我试图进一步,让Lambda(来自亚马逊网络服务)每天为我自动完成。但我遇到了一个问题,我坚持下去。

我不知道如何在不使用client_secrets.json文件的情况下从脚本验证OAuth 2.0,并且如果没有其他方式来执行操作,应该离开.json文件以便让它自己进行身份验证。



正如它解释这里因为我没有使用我需要使用的Google服务之一:

  from oauth2client.service_account import ServiceAccountCredentials 

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

凭证= ServiceAccountCredentials.from_json_keyfile_name(
'/path/to/keyfile.json',范围)

但我没有文件路径。

解决方案

如果您查看 ServiceAccountCredentials at https://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html#oauth2client.service_account.ServiceAccountCredentials

你会看到 .from_json_keyfile_name 有一个构造函数 from_json( json_data)。这应该做你需要的。


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.

解决方案

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.

这篇关于Python - 如何验证从AWS Lambda咨询Google Analytics?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆