I'm trying to create a google script which automatically adds images to a google online album using the photoslibrary.googleapis.com rest api.
The first step involves uploading the files using the uploads function. I've tried authenticating the request using the script's OAuthToken
"Authorization": "Bearer " + ScriptApp.getOAuthToken()
But I get the following error response:
{ "code": 16, "message": "Authentication session is not defined." }
Is there a way to authenticate a google script rest request with the credentials of the user that is running it, so the photoslibrary.googleapis.com can be automatically accessed, granted that the owner of the galleries is the same as the one running the script?
function photoAPI_upload(blob) {
var api = "https://photoslibrary.googleapis.com/v1/uploads";
var headers = {
"Authorization": "Bearer " + ScriptApp.getOAuthToken(),
"contentType": "application/octet-stream",
'X-Goog-Upload-File-Name': blob,
'X-Goog-Upload-Protocol': "raw",
};
var options = {
method: "post",
headers: headers,
payload: blob
}
var response = UrlFetchApp.fetch(api, options);
Logger.log('upload-token' + response.getContentText());
return response.getContentText();
}