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

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.

Here is the code:

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

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.

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top