My goal:
I am trying to implement the Google Calendar's API acl.list() in a Google Script using the UrlFetchApp.fetch() function.
Issue:
The Google script itself has an OAuth token when it runs. However, the problem arises when the UrlFetchApp.fetch() function is used for a separate HTTP request which also requires an OAuth token to function properly.
Query:
Is there a way to reuse the token already used by my authorized apps-script in manually called HTTP requests within that script? If not, how can I generate a token specifically for this request?
Motivation:
The ContactsApp is user-friendly but lacking the necessary ACL functionality that I require.
Snippet of my code (currently not functioning):
function pleaseAssist() {
var calId = "MY_CORRECT_CALENDAR_ID";
var url = "https://www.googleapis.com/calendar/v3/calendars/" + calId + "/acl";
var data = {
"foo" : "foo data",
"bar" : "data bar...",
};
var payload = JSON.stringify(data);
var options = {
"method" : "POST",
"contentType" : "application/json",
"payload" : payload
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}
This code snippet throws an exception: "401 Login Required" which makes sense...
Grateful in advance for any assistance rendered.