Google 应用程序脚本错误:“您无权调用保护" [英] Google apps script error: "You do not have permission to call protect"

查看:41
本文介绍了Google 应用程序脚本错误:“您无权调用保护"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying out my first Google Sheets Apps Script. I'm trying to make a custom function (via a bound script) that will check if the cell it's in is protected. If it is protected, it should change the cell's value to (for now at least) the protection type.

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

I can successfully run the simple demo script in the docs:

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

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

But when calling Range::protect, I can an error

"You do not have permission to call protect"

这是函数

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

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

I also get the same permissions error with some other functions, e.g. Session.getEffectiveUser(). I figured that since this is a bound custom function and I'm the (only) sheet owner, I'd be able to call these methods. What am I missing? Thanks.

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

I've tried copy-pasting the script into the script editor of a new sheet, since some posts have had luck with that, but no luck for me.

推荐答案

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

Custom function run anonymously so the implicit consequence is that they can not do anything that requires authorization.

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

Changing a range protection requires an authorization , that's why you can't use it and get the message you get...

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

Same situation for getEffectiveUser(), it requires an authorization too.

文档中的参考:

与大多数其他类型的 Apps 脚本不同,自定义函数从不询问用户授权访问个人数据.因此,他们可以仅调用无权访问个人数据的服务

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 应用程序脚本错误:“您无权调用保护"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆