My intent:
I want to call Google Calendar's API acl.list() from a google script using UrlFetchApp.fetch() function.
Problem:
My Google script it self has oauth token when it runs. Problem is that UrlFetchApp.fetch() is a separate http request which requires oauth token to work.
Question:
How do I reuse token used by my (already authorized) apps-script in http request called manually from that script. Is it possible? If not, then how do I generate token for this request?
Rationale:
The ContactsApp is pleasant to work with but it does not have needed ACL functionality yet.
My (not working) code:
function pleaseHelp() {
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);
}
gives exception: "401 Login Required" obviously...
Thanks in advance for any help.