0
我跟着導遊在這裏:https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/web-js查詢谷歌分析報告使用郵遞員403
它工作正常。但我想嘗試與郵差。
這是我的嘗試: 請求:https://analyticsreporting.googleapis.com/v4/reports:batchGet
頁眉: 授權:承載ya29.Ezxxxxx
內容類型:應用程序/ JSON
身體:
{"reportRequests": [
{
"viewId": "viewid",
"includeEmptyRows": true,
"dateRanges": [
{
"startDate": "7daysAgo",
"endDate": "today"
}
],
"metrics": [
{
"expression": "ga:sessions"
}
],
"dimensions": [
{
"name": "ga:date"
}
]
}
]
}
但我得到錯誤:
{
"error": {
"code": 403,
"message": "User does not have any Google Analytics account.",
"status": "PERMISSION_DENIED"
}
}
令牌我從代碼中得到這樣的:
var content = require('./project_key.json');
var jwt = new googleapis.auth.JWT(
content.client_email,
null,
content.private_key,
['https://www.googleapis.com/auth/analytics.readonly']);
jwt.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
}
var access_token = tokens.access_token;
res.send(access_token);
看來權限設置。但我不知道如何設置它。我可以從「私鑰文件」中獲取令牌。
任何建議真的很感激。 謝謝,