Python从密钥分析嵌入API提取访问令牌
我以前没有真正使用过Python,但这是Google给你的唯一一个例子 我已经测试了我的JS/HTML代码,使用来自的临时令牌向我们站点上的客户显示分析仪表板。一切正常,但当然代币只能持续一个小时 他们为您提供的用于提取密钥的Python脚本是:Python从密钥分析嵌入API提取访问令牌,python,google-analytics,Python,Google Analytics,我以前没有真正使用过Python,但这是Google给你的唯一一个例子 我已经测试了我的JS/HTML代码,使用来自的临时令牌向我们站点上的客户显示分析仪表板。一切正常,但当然代币只能持续一个小时 他们为您提供的用于提取密钥的Python脚本是: # service-account.py import json from oauth2client.client import SignedJwtAssertionCredentials # The scope for the OAuth2 re
# service-account.py
import json
from oauth2client.client import SignedJwtAssertionCredentials
# 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'
# Load the key file's private data.
with open(KEY_FILEPATH) as key_file:
_key_data = json.load(key_file)
# Construct a credentials objects from the key data and OAuth2 scope.
_credentials = SignedJwtAssertionCredentials(
_key_data['client_email'], _key_data['private_key'], SCOPE)
# Defines a method to get an access token from the credentials object.
# The access token is automatically refreshed if it has expired.
def get_access_token():
return _credentials.get_access_token().access_token
我已经将json密钥的文件路径更改为文件的位置,并且已经为Analytics API安装了所需的python客户端,并检查了它的安装情况
当我在浏览器中使用python脚本时,会出现一个内部服务器错误,这是可以理解的,但是如何将密钥放入HTML/PHP页面呢?或者是否有其他PHP脚本可以提取密钥
他们为前端(钥匙应该放在哪里)提供的代码是:
gapi.analytics.ready(function() {
/**
* Authorize the user with an access token obtained server side.
*/
gapi.analytics.auth.authorize({
'serverAuth': {
'access_token': ' [ ACCESS TOKEN HERE] '
}
});