Google App Script One Shot Authentication

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

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?

回答1:

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()



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!