【发布时间】:2016-07-14 16:59:22
【问题描述】:
我似乎无法让 EMBED-API 服务器端授权演示工作: https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/
在演示中它说如下:
安装库后,您可以添加以下 python 模块 到您的项目并调用 get_access_token() 方法来获取 可用于授权 Embed API 的访问令牌。
# service-account.py
from oauth2client.service_account import ServiceAccountCredentials
# The scope for the OAuth2 request.
SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'
# The location of the key file with the key data.
KEY_FILEPATH = 'path/to/json-key.json'
# Defines a method to get an access token from the ServiceAccount object.
def get_access_token():
return ServiceAccountCredentials.from_json_keyfile_name(
KEY_FILEPATH, SCOPE).get_access_token().access_token
我已经成功完成了前面的所有步骤,但是这一步我无法理解。我把这段代码放在哪里?好像应该放在 .py 文件中。
有人可以帮忙吗?
【问题讨论】:
标签: python google-analytics-api