I'm trying to call Ganalytics from app-script, but I get an error about missing scopes.
I couldn't find documentation about where I should put the "scope" property (it just says under request options
).
Is this the right syntax?
function getEventsFromAnalytics() {
var url = 'https://analyticsdata.googleapis.com/v1beta/properties/1234:runReport';
var token = ScriptApp.getOAuthToken();
Logger.log(`token is ${token}`)
var auth = "Bearer " + token;
var myHeaders = {
"Authorization": auth
}
var requestOptions = {
'contentType': 'application/json',
'headers': myHeaders,
'method' : 'post',
'payload' : rawdata,
'followRedirects': true,
'muteHttpExceptions' : true,
'scope': 'https://www.googleapis.com/auth/analytics.readonly'
};