我正在尝试将我的 Google 应用程序脚本/Google 电子表格设为模板。我遇到的唯一问题是身份验证。如果您尝试运行任何脚本,它都会对自身进行身份验证,但我需要它将自身部署为 Web 应用程序。我正在使用:
function startWebApp() {
//Setup the webapp service
var service = ScriptApp.getService();
service.enable(service.Restriction.ALL);
Logger.log("WebApp Started");
}
当我从电子表格中创建的菜单运行它时,它有一个很好的前端界面,它会要求授权,但下次运行它时(我读到你需要运行一个函数两次,一次授权脚本,第二次实际运行该函数)你得到
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.
是否有更好的方法或不同的方法来允许脚本自行发布,或者我只是做错了?
最佳答案
您需要重新授权。确保分离功能。
function inv(){
ScriptApp.invalidateAuth();
}
https://developers.google.com/apps-script/reference/script/script-app#invalidateAuth()
关于javascript - Google App 脚本一键身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21266917/