【发布时间】:2021-07-27 18:21:50
【问题描述】:
我正在运行这段代码:
var auth = "Bearer " + token;
var myHeaders = {
"Authorization": auth
}
var rawdata = JSON.stringify({
"dimensions": [
{
"name": "appVersion"
},
{
"name": "eventName"
}
],
"metrics": [
{
"name": "eventCount"
}
],
"dateRanges": [
{
"startDate": "30daysAgo",
"endDate": "yesterday"
}
],
"orderBys": [
{
"dimension": {
"orderType": "ALPHANUMERIC",
"dimensionName": "appVersion"
}
},
{
"dimension": {
"orderType": "ALPHANUMERIC",
"dimensionName": "eventName"
}
}
],
"metricAggregations": [
"TOTAL"
]
});
var requestOptions = {
'contentType': 'application/json',
'headers': myHeaders,
'method' : 'post',
'payload' : rawdata,
'followRedirects': true,
'muteHttpExceptions' : true
};
var response = UrlFetchApp.fetch(url, requestOptions);
Logger.log(`response is ${response}`)
var result = JSON.parse(response.getContentText());
var dataSet = result;
Once I had created a trigger, we saw 100% failure rate.
response is {
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED"
}
}
并得到这个错误:
"error": {
"code": 403,
"message": "Google Analytics Data API has not been used in project 548594456844 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/analyticsdata.googleapis.com/overview?project=548594456844 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console API activation",
"url": "https://console.developers.google.com/apis/api/analyticsdata.googleapis.com/overview?project=548594456844"
}
]
},
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "SERVICE_DISABLED",
"domain": "googleapis.com",
"metadata": {
"consumer": "projects/548594456844",
"service": "analyticsdata.googleapis.com"
}
}
]
}
}
但我无权访问此 GCP 项目。 这是否意味着 GCP 必须调用 GA4 API?
如果我无权访问此 GCp 项目(应用程序脚本的默认项目)- 我该如何解决?
【问题讨论】:
标签: google-apps-script google-cloud-platform oauth-2.0 google-analytics-api google-analytics-4