我想在我的管理面板上显示我的谷歌分析。我关注了google analytics api .我创建了服务端授权并下载了 json 数据
{
"type": "service_account",
"project_id": "xxxx",
"private_key_id": "xxxxxxxxxxxxxxxxx",
"private_key": "-----BEGIN PRIVATE KEY-----xxxxxxxxx-----END PRIVATE KEY-----\n",
"client_email": "xxxxxxxxxxxxxx",
"client_id": "xxxxxxxxxxxxxxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url":"xxxxxx"
}
在创建上面的 json 并复制该教程中提到的 js 代码之后。
在js代码中要求
gapi.analytics.auth.authorize({
'serverAuth': {
'access_token': '{{ ACCESS_TOKEN_FROM_SERVICE_ACCOUNT }}'
}
});
这里的问题是我找不到 ACCESS_TOKEN。我只是用私钥、客户端 ID、私钥 ID 替换并尝试但它显示 401 错误。
可能是它的愚蠢问题。但我不知道如何得到这个。请有人帮助我。
最佳答案
您是否调用了 getAuthResponse
?此方法返回您需要使用的访问 token 。
getAuthResponse()
Returns: Object
Gets authentication data returned by the original authorization request. The returned object includes the access token, which can be usually to manually make authenticated requests.
请参阅此处 https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference?hl=en
关于javascript - 如何在我的后端显示我网站的谷歌分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34437451/