简体   繁体   中英

Google App Script One Shot Authentication

I'm trying to make my Google App Script/Google Spreadsheet a template. The only problem I'm having is with authentication. If you try to run any of the script it will authenticate itself but I need it to deploy itself as a WebApp. I'm using:

function startWebApp() {
//Setup the webapp service
var service = ScriptApp.getService();
service.enable(service.Restriction.ALL);
Logger.log("WebApp Started");
}

and when I run this from a menu I've created in the spreadsheet, so it has a nice front-end interface, it will ask to authorize but then the next time you run it (I've read that you need to run a function twice, once to authorize the script and the second time actually runs the function) you get

Your one shot authorization state is not valid. The script must be reauthorized. The script's reauthorization can be triggered by calling ScriptApp.invalidateAuth() and rerunning the script.

Is there a better way or different way to allow a script to publish itself or am I just doing it wrong?

You need to reauthorize it. Be sure to separate function.

function inv(){
  ScriptApp.invalidateAuth();
}

https://developers.google.com/apps-script/reference/script/script-app#invalidateAuth()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM