4

我想从谷歌分析中检索数据。我已经在控制台中创建了一个服务帐户,并且我正在使用 Google 的 Python ( hello_analytics_api_v3.py) 代码来访问数据。

我已将其复制client_secrets.json到我的文件夹中,但出现此错误:

*SystemExit: 
WARNING: Please configure OAuth 2.0
To make this sample run you will need to populate the client_secrets.json file
found at:*

我应该怎么办?我正在使用 Python 2.7。

4

5 回答 5

11

Ensure the terminal is pointing to the same path directory as your client_secrets.json file.

i.e. type pwd in the console you're using to call the script and the output should match the directory of where client_secrets.json is stored.

于 2013-04-19T16:05:35.350 回答
3

我遇到了这个确切的问题,并删除了我的项目的凭据,并使用“OAuth 客户端 ID”选项创建了新的凭据。按照此页面的第一步操作 closley https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/installed-py

我还在google The Lines提供的示例代码中发现了一个语法错误:

print 'View (Profile): %s' % results.get('profileInfo').get('profileName')
print 'Total Sessions: %s' % results.get('rows')[0][0]

应该读:

print ('View (Profile): %s' % (results.get('profileInfo').get('profileName')))
print ('Total Sessions: %s' % (results.get('rows')[0][0]))

至少这为我解决了。此外,请确保 client_secrets.json 与您的 python 脚本位于同一目录中。

于 2016-01-17T04:19:25.187 回答
2

https://developers.google.com/youtube/v3/guides/uploading_a_video的示例代码中,调用作为相对路径flow_from_clientsecrets()传递。CLIENT_SECRETS_FILE

要修复它,请强制CLIENT_SECRETS_FILE参数为绝对路径:

def get_authenticated_service(args):
  flow = flow_from_clientsecrets(
    os.path.abspath(os.path.join( 
      os.path.dirname(__file__),CLIENT_SECRETS_FILE)),
    scope=YOUTUBE_UPLOAD_SCOPE,
    message=MISSING_CLIENT_SECRETS_MESSAGE)
于 2016-07-23T21:28:35.853 回答
1

我收到此错误是因为我在 client_id 和 client_secret 中仍然有方括号。它应该只是没有括号的字符串。

于 2015-11-20T14:37:21.843 回答
0

如果您使用的是 Windows 系统,请按照以下步骤操作:

  1. 将您的文件 ( client_secrets.json) 放在目录 (C:) 或 (D:) 中。
  2. 在你的 Python 文件中定义你的变量,如下所示 CLIENT_SECRETS_FILE = "\client_secrets.json":Python 将在根 C: 或 D: 中搜索 json 文件并找到它。

我对 youtube 的 Google API 有同样的问题,我就这样解决了。

于 2017-01-15T11:31:03.193 回答