我正在尝试将自定义社区连接器连接到谷歌分析 4,以便从分析中获取数据并能够在应用脚本中对其进行修改,然后将其发送到数据工作室。但是,我很难从谷歌分析中连接和检索数据。
错误:
{ error:
{ code: 403,
message: 'Google Analytics Data API has not been used in project 640397821842 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/analyticsdata.googleapis.com/overview?project=640397821842 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: [ [Object], [Object] ] } }
我设置了范围
"oauthScopes": [
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/analytics.readonly"
],
我试图测试的代码:
function testFetch(){
const options = {
entry: { propertyId: 263290444},
"dateRanges": [{ "startDate": "2020-12-01", "endDate": "2021-03-01" }],
"dimensions": [{ "name": "country" }],
"metrics": [{ "name": "activeUsers" }],
// etc.
}
var response = UrlFetchApp.fetch(
'https://analyticsdata.googleapis.com/v1alpha:runReport', {
method: 'POST',
muteHttpExceptions: true,
headers: {
Authorization : `Bearer ${ScriptApp.getOAuthToken()}`
},
contentType: 'application/json; charset=utf-8',
payload: JSON.stringify(options)
});
var result = JSON.parse(response.getContentText());
console.log(result);