gpt4 book ai didi

javascript - 使用 Google 脚本和电子表格创建时间触发器

转载 作者:行者123 更新时间:2023-11-29 14:47:21 27 4
gpt4 key购买 nike

我想使用 Google 脚本为我的工作表创建一个简单的时间触发器,我按照 docs 中的描述进行操作,但是当我调用函数时出现错误:

Google Apps: You do not have permission to call newTrigger

我尝试在互联网上寻找解决方案,但没有得到任何结果。有人可以帮我吗?谢谢!

附言我的代码:

 ScriptApp.newTrigger("consolius")
.timeBased()
.everyMinutes(1)
.create();

function consolius() {
SpreadsheetApp.getUi().alert('Hello, world!');
}

最佳答案

评论中提到的限制不适用于您的用例,它们适用于 add-ons only .右边info is here .

但即使您实际上可以创建一个计时器触发器来每分钟运行一个函数,您也不能使用您尝试的方法,因为计时器触发器无法与 Ui 交互。

如果您查看错误通知,您会看到该消息:

Details:
Start Function Error Message Trigger End
7/3/15 4:08 PM consolius Cannot call SpreadsheetApp.getUi() from this context. (line 26, file "clean sheet") time-based 7/3/15 4:08 PM

另一个兴趣点:您应该在函数中包含创建触发器的脚本,否则每次您在该项目中运行任何其他函数时都会创建一个新触发器,包括触发调用,这将很快变得非常困惑! (每次调用任何函数时都会执行“全局”的所有内容)。

最后但同样重要的是:您不能在自定义函数中使用此类代码,它必须位于您从菜单或按钮运行的脚本中。

关于javascript - 使用 Google 脚本和电子表格创建时间触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31206561/

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