Google 应用程序脚本 运行s 处于调试模式,而不是 运行 模式

Google app script runs in debug mode, not in run mode

你好 Google 脚本专家,我是 google 脚本的新手,正在尝试 google 文档中与 HTTP POST 相关的内容。

我有一个 google 应用程序脚本,它在打开 google 文档时发送 post 请求 (API)。

function onOpen() {
var ui = DocumentApp.getUi(); // Same variations.
  var actDoc = DocumentApp.getActiveDocument();
  var docID = actDoc.getId();
  var repeater = 0;
  var data = {
                'bstask':  text,
                'docid': docID
              };
   console.log(data);
   var options = {
         'method' : 'post',
                'contentType': 'application/json',
                // Convert the JavaScript object to a JSON string.
                'payload' : JSON.stringify(data)
              };
              ui.alert("Sending request with the payload" + data.bstask + " and " + data.docid);
              var response = UrlFetchApp.fetch('https://test.com/path', options);
              ui.alert("Response is: " + response.getResponseCode());
              if (response.getResponseCode() == 200) {
                Logger.log(response.getContentText() + response.getAllHeaders());
                ui.alert('Yey!! Document refreshed.');
              }
              else{
                ui.alert('Opps!! Document refresh failed.'+ response.getContent());
              }
  
}

此脚本用于为用户提供一个选项,以便在打开或刷新文档时更新文档。当我在调试模式下测试它时,该脚本运行良好并调用 API 。但是,当我希望在打开文档时执行此脚本时,它不会调用 API 并且 UI 提示的其余部分工作正常。我在这里遗漏了什么或脚本有问题吗?非常感谢任何帮助!!

Simple Triggers – Restrictions

Because simple triggers fire automatically, without asking the user for authorization, they are subject to several restrictions:

  • They cannot access services that require authorization. For example, a simple trigger cannot send an email because the Gmail service requires authorization, but a simple trigger can translate a phrase with the Language service, which is anonymous.

换句话说,UrlFetchApp.fetch()调用不会在打开文档时执行,因为它需要授权。您也应该能够在执行日志中看到此失败。