Google应用脚本错误

Google应用脚本错误

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

问题描述

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



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

 函数DOUBLE(输入){
返回输入* 2;
}

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

 您无权调用保护

以下是函数:

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

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



我试着将脚本复制粘贴到新工作表的脚本编辑器中,因为有些帖子运气不错,但对我来说没有运气。

解决方案

自定义函数匿名运行,所以隐含的结果是他们无法做任何需要授权的事情



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


$ b $ p getEffectiveUser()的情况也是如此,它也需要授权。






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;
}

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

"You do not have permission to call protect"

Here's the function

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

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...

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

Reference in docs :

这篇关于Google应用脚本错误:“您无权拨打保护电话”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:09