Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何通过URLFetch类使用Google应用程序脚本调用外部API_Google Apps Script - Fatal编程技术网

Google apps script 如何通过URLFetch类使用Google应用程序脚本调用外部API

Google apps script 如何通过URLFetch类使用Google应用程序脚本调用外部API,google-apps-script,Google Apps Script,现在的问题是,当我使用这个URLFetch类调用外部API时,这是不起作用的。 在浏览器控制台中显示了一个错误: 未捕获的TypeError:无法读取未定义的属性“fetch” 根据Kriggs在评论中所说的,您似乎正在尝试在客户端的.js文件中使用UrlFetchApp.fetch。您想在服务器的.gs文件中进行此调用。这个checkACBalance函数在哪里?在GAS code.gs文件中的HTML代码之间?我有三个文件用于此。html为Sidebar.html,Javascript为Si

现在的问题是,当我使用这个URLFetch类调用外部API时,这是不起作用的。 在浏览器控制台中显示了一个错误:

未捕获的TypeError:无法读取未定义的属性“fetch”


根据Kriggs在评论中所说的,您似乎正在尝试在客户端的.js文件中使用UrlFetchApp.fetch。您想在服务器的.gs文件中进行此调用。

这个checkACBalance函数在哪里?在GAS code.gs文件中的HTML代码之间?我有三个文件用于此。html为Sidebar.html,Javascript为SidebarJS.html,CSS样式表为Stylesheet.html。SidebarJS.htmlc中的checkACBalance函数你能用合适的例子解释一下吗?
function checkACBalance() {
  try{
    var url ="http://sms.mydomain.com/api/balance.php";
    alert(url);
    var payload = {authkey:'d5558466554f11aa909d565ede677d40', route:'1'};
    alert(payload);
    var payload_json = encodeURIComponent(JSON.stringify(payload));
    alert(payload_json);
    var options =  {method:"POST",contentType:"application/json",payload:payload_json,muteHttpExceptions:true};
    var result = UrlFetchApp.fetch(url, options);
    var response = result.getContentText();
    alert(response)
    var res_code = result.getResponseCode();
    alert(res_code)
  }catch(e){
    alert(e)
  }
}