来自onOpen事件/触发的HTTP发布 [英] HTTP Post from the onOpen event/trigger

查看:49
本文介绍了来自onOpen事件/触发的HTTP发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google Apps脚本的onOpen事件中执行HTTP发布时遇到问题.我想做的是向另一个已部署的脚本发送通知,通知它有人打开了我们的一个电子表格.我希望即使有人复制电子表格时也可以保留此功能,以便我们也可以跟踪这些位置.

I'm having an issue with doing an HTTP Post in the onOpen event in google apps script. What I'm trying to do is send a notification to another deployed script that someone has opened one of our spreadsheets. I'd like this functionality to persist even when someone copies the spreadsheet so that we can track where those are as well.

我的问题是,如果我从onOpen事件中调用UrlFetchApp.fetch(url,options),则会收到错误-执行失败:您没有调用fetch的权限",但是如果我创建一个使用打开电子表格时触发的ui触发.这种方法的问题在于,在复制电子表格时不会复制那些触发器.

My problem is that if I call UrlFetchApp.fetch(url, options) from the onOpen event, I get the error - "Execution failed: You do not have permission to call fetch" however the fetch does work if I create a trigger using the ui that fires when the spreadsheet is opened. The problem with this approach is those triggers are not copied when the spreadsheet is copied.

对于可能的解决方案或简单的解决方法的任何建议,将不胜感激.

Any suggestions for a possible solution or a simple workaround would be greatly appreciated.

谢谢,马克.

推荐答案

触发器有两种类型-简单触发器和可安装触发器. onOpen 是一个简单的触发器,在简单的触发器中可以执行的操作有一些限制,而执行UrlFetch就是其中之一.您可以阅读有关简单&的更多信息. https://developers.google.com/apps-script/understanding_triggers

There are two types of triggers - simple and installable. The onOpen is a simple trigger and there are limitations on what you can do within a simple trigger and doing an UrlFetch is one of them. You can read more about simple & installable triggers at https://developers.google.com/apps-script/understanding_triggers

这篇关于来自onOpen事件/触发的HTTP发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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