gpt4 book ai didi

google-apps-script - 谷歌应用程序脚本错误 : "You do not have permission to call protect"

转载 作者:行者123 更新时间:2023-12-05 01:02:08 28 4
gpt4 key购买 nike

我正在尝试我的第一个 Google 表格应用脚本。我正在尝试制作一个自定义函数(通过绑定(bind)脚本)来检查它所在的单元格是否受到保护。如果它受到保护,它应该将单元格的值更改为(至少现在)保护类型。

我可以成功运行文档中的简单演示脚本:

function DOUBLE(input) {
return input * 2;
}

但是当调用 Range::protect 时,我会报错

"You do not have permission to call protect"

这是函数

function isProtected() {
var range = SpreadsheetApp.getActiveRange();
var protection = range.protect();
return protection.getProtectionType();
}

我也遇到了与其他一些功能相同的权限错误,例如Session.getEffectiveUser()。我想,由于这是一个绑定(bind)的自定义函数并且我是(唯一的)工作表所有者,所以我可以调用这些方法。我错过了什么?谢谢。

我尝试将脚本复制粘贴到新工作表的脚本编辑器中,因为有些帖子很幸运,但我没有运气。

最佳答案

自定义函数匿名运行,因此隐含的结果是他们不能做任何需要授权的事情

更改范围保护需要授权,这就是为什么你不能使用它并得到你得到的消息......

getEffectiveUser()也是同样的情况,也需要授权。

Reference in docs :

Unlike most other types of Apps Scripts, custom functions never ask users to authorize access to personal data. Consequently, they can only call services that do not have access to personal data

关于google-apps-script - 谷歌应用程序脚本错误 : "You do not have permission to call protect",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36365447/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com