基于 this documentation,我正在尝试在 Google Apps 脚本中创建 ga4 属性:
var service = getService();
if (service.hasaccess()) {
var apiURL = "https://analyticsadmin.googleapis.com/v1alpha/properties";
var resource = {
"displayName": "Automating ga4 creation","timeZone": "America/Los_Angeles","currencyCode": "USD","parent": "accounts/123"
};
Logger.log(resource);
var headers = {
"Authorization": "Bearer " + getService().getaccessToken()
};
var options = {
"headers": headers,"method" : "POST","muteHttpExceptions": true,"resource": resource
};
var response = UrlFetchApp.fetch(apiURL,options);
Logger.log(response);
} else {
var authorizationUrl = service.getauthorizationUrl();
Logger.log('Open the following URL and re-run the script: %s',authorizationUrl);
Browser.msgBox('Open the following URL and re-run the script: ' + authorizationUrl)
}
}
但我收到此错误:
"error": {
"code": 400,"message": "The value for the 'parent' field was invalid but must be in format 'accounts/123'.","status": "INVALID_ARGUMENT"
}
}
,我的回复格式没问题
这是我的Logger.log(resource)
:
{parent=accounts/123,displayName=Automating ga4 creation,currencyCode=USD,timeZone=America/Los_Angeles}
注意:
1- 出于隐私考虑,我已将我的 Google Analytics(分析)帐户 ID 替换为 123
。
2- OAuth 有效,因为我已经能够列出属性。
提前致谢。