Вопрос

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