为什么无法在onOpen触发器中调用UrlFetchApp? [英] Why UrlFetchApp fails to be called in an onOpen trigger?

查看:77
本文介绍了为什么无法在onOpen触发器中调用UrlFetchApp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google电子表格加载时发出HTTP POST请求.

I am trying to make an HTTP POST request when Google Spreadsheet loads.

我已经在菜单下拉菜单中将HTTP POST请求用作功能,但我 无法使其与onOpenonInstall一起使用.

I have gotten my HTTP POST request working as a function in a menu dropdown but I can't get it to work with onOpen or onInstall.

这是代码:

    function onOpen(){
      var url = "http://example.com/collect";
      var options = {
        "method": "post",
        "payload": {
          "v":"1",             
          "data1":"hello", 
          "data2":"5553",   
          "data3":"test"
        }
      }
      Logger.log('worked');
      UrlFetchApp.fetch(url, options);
    }

加载电子表格时是否可以发出HTTP POST请求?如果是这样,您是否发现我的代码有什么问题?

Is it possible to make an HTTP POST request when a spreadsheet loads? If so, do you see anything wrong with my code?

推荐答案

如果您阅读有关权限和简单触发器的文档,您将了解到简单的触发器无法执行任何需要授权的事情,因为它们是在授权下运行的并静默地"执行用户在键盘上".

If you read the documentation about permissions and simple triggers, you will learn that simple triggers can't do anything that requires authorization because they run under the authority of the "user at the keyboard" and do it silently.

更改函数名称并创建将以您自己的身份执行的可安装的onOpen触发器.

Change the function name and create an installable onOpen trigger that will be executed as yourself.

这篇关于为什么无法在onOpen触发器中调用UrlFetchApp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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