我似乎无法获取嵌入-API服务器端授权的演示工作: https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/嵌入-API,谷歌Analytics(分析),服务器端授权
在演示中,它说以下内容:
安装库之后,您可以将以下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文件中。
有人可以帮忙吗?
谢谢你马特。我只想在我的网站上创建一个仪表板:http://web-tailor.nl/dashboard/这个仪表板现在可以工作,但我希望它有一个固定的视图,无需登录。是否有一种方法可以实现这个?我有点小菜,但我没有服务器。 – PaulusfranCircus
如果没有服务器,将无法使用[服务帐户](https://developers.google.com/identity/protocols/OAuth2ServiceAccount)。仔细研究各种[OAuth 2.0场景](https://developers.google.com/identity/protocols/OAuth2#scenarios)。服务帐户需要一个安全的地方运行。 – Matt