The file is shared with a google account as the editor.
The webapp is published as mentioned in the question/subject.
The logs for Session.getEffectiveUser()
and Session.getAcitveUser()
show the editor's emails address when he runs a script and because of that, a couple of file accesses throw an error - permission denied.
The script is run upon the click of a button. I've tried setting it as a library as well, but I got the same permission issue.
Besides broader and deeper knowledge, what am I missing here?
CodePudding user response:
The web app deployment settings like "Run as me" and "By Anyone" only have effect over doGet
and doPost
functions, and only when they are called by HTTP requests (when they are called by using the web app URL).
If you have set a button on a spreadsheet by inserting a drawing and assigning a function to it, the web app deployment settings will not have any effect over a function that directly calls the Google Apps Scripts services like SpreadsheetApp, but might work if the function use the UrlFetchApp service to make the HTTP request to your web app.
Here is an oversimplified Google Apps Script server side code (.gs) to make a call to a web app:
function callMyWebApp(){
const url = 'put here your web app URL';
const response = UrlFetchApp.fetch(url); // This will do a GET request
// do something with the response
}
An easier approach might be to use an installable trigger as it's not required to deal with another "complexity layer" as it doesn't require to add another service to your project (UrlFetchApp), it will not be necessary to deploy a web-app and make a new version every time that you update your code, but if you want to keep at minimum the scopes to be authorized by the editors, you will have to use the web app approach.
Related