Creating time-based trigger from WebApp

2019-09-07 07:15发布

问题:

I am trying to create a time-based trigger from a Google Apps Script published as a WebApp.

Update: this WebApp shall be run as the user accessing it, not as the Apps Script owner.

Whenver I even try to access the ScriptApp services, I get an error in the frontend:

Authorization is required to perform that action.

Sample code to reproduce this would be:

function doGet(request) {
  ScriptApp.newTrigger('test');
  return ContentService.createTextOutput("OK");
};

function test() {
  // noop
}

Is this something that is not possible? Is it possible to somehow automatically add a trigger that runs a method based on time with the user giving the authorization?

回答1:

Under what credentials is your web app run ? As the user running the app or as yourself. From the error, it looks like it is run under the author's credentials. In this case, you should authorize the application explicitly before you can distribute the URL. To do so, open the script editor and choose any function and try to run the function using the little 'play' button in the script editor. You'll be asked to provide permissions after which you can use the Ui App