python - Python-如何进行身份验证从AWS Lambda咨询Google Analytics(分析)?

标签 python amazon-web-services google-analytics google-oauth aws-lambda

我有一个python脚本来查询Google Analytics(分析)中的某些数据,但我想做得更进一步,让Lambda(来自Amazon Web Services)每天自动为我做这件事。但是我遇到一个问题,我一直坚持下去。

我不知道如何在不使用client_secrets.json文件的情况下从脚本进行OAuth 2.0身份验证,并且如果没有其他方法可以执行此操作,那么我应该如何以及在何处保留.json文件以便对其进行身份验证。

正如它解释here一样,因为我未使用Google服务之一,所以我需要使用:

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)


但我没有该文件的路径。

最佳答案

如果您在https://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html#oauth2client.service_account.ServiceAccountCredentials上查看ServiceAccountCredentials的文档

您会看到,除了.from_json_keyfile_name之外,还有一个构造函数from_json(json_data)。那应该做您需要的。

关于python - Python-如何进行身份验证从AWS Lambda咨询Google Analytics(分析)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44975002/

相关文章:

google-analytics - 从Google Analytics(分析)切换到跟踪代码管理器

javascript - 是否可以从 main.js 访问 View 中声明的 js 变量?

Python DataFrame - 根据同一数据帧的列中的值选择数据帧行

python - 重复使用 GradientTape 进行多个雅可比计算

php - ZipArchive::close():无法在 AWS EC2 Linux 中创建临时文件

amazon-ec2 - 如何查找我当前正在使用多少EBS分配大小

python - 与 DynamoDB 库 Boto3 的事务

regex - 从 Google Analytics 中排除 IP - 为什么这不是有效的正则表达式?

python - PyQt4 需要将 DLL 移动到包根目录

python - 如何编写一个程序来使用从 9 到 1 的数字获取 2016 的所有方法?