且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

google apps脚本:删除和恢复保护

更新时间:2023-12-05 20:52:52

似乎没有简单的方法,因为从菜单运行的功能始终以用户在键盘上"执行.

There seems to be no easy way to do this, because functions run from the menu is always executed as "user at the keyboard".

一种解决方法是将网络应用发布为始终以"所有者.然后,此Web应用程序将写入 doPost()上的受保护范围.然后,链接到菜单UI的功能将使用 UrlFetch 以发布到已发布的Web应用程序.您还可以使用带有密码/随机生成的数字的一些基本身份验证来拒绝来自脚本外部的请求.

One workaround is to publish a Web App to always "Execute as" Owner. This web app will then write to protected ranges on doPost(). The function linked to Menu UI will then use UrlFetch to POST to the published Web App. You can also use some basic authentication with a password/randomly generated numbers to reject requests from outside your script.

此外,如果您不信任编辑者不要弄乱您的绑定脚本,***将其作为私有加载项发布,这样源代码就不容易获得.

Also, If you don't trust editors not to mess with your bound script, It's better to publish it as a private add-on, where the source code is not easily accessible.