首页 > 解决方案 > Google 表格中的 API 调用 Google Apps 脚本返回代码 500

问题描述

我正在尝试调用 cutt.ly 的 api 来缩短网址。将 cal 粘贴到 Safari 中时,我得到了所需的响应;但是,当我在我的 Google Apps 脚本项目中使用 URLFetch 拨打电话时(为 Google 表格插件制作),我只得到 500 的代码。

我在 Safari 中尝试了以下 url,它返回了所需的信息:https ://cutt.ly/api/api.php?key=[APIKEY]&short=https://www.ThisIsMyReallyLongLink.com&name=MyTestLinkThatIsUnused

但是,如果我像这样在 Google Apps 脚本中进行调用,我只会得到代码 500: UrlFetchApp.fetch(" https://cutt.ly/api/api.php?key=[APIKEY]&short=https:// www.ThisIsMyReallyLongLink.com&name=MyTestLinkThatIsUnused ");

具体错误是:

“例外:对https://cutt.ly/api/api.php?key=[APIKEY]&short=https://www.ThisIsMyReallyLongLink.com&name=MyTestLinkThatIsUnused的请求失败返回代码 500”

cutt.ly API 的文档位于此处https://cutt.ly/cuttly-api

有没有人对我为什么只在 Google Apps 脚本中收到此错误以及如何解决有任何想法。如果可能的话,我想避免做这样的事情 UrlFetchApp.fetch(url, {"muteHttpExceptions": true}) 以确保我捕获所有异常并正确处理。

function test(){ 
  var response = UrlFetchApp.fetch("cutt.ly/api/api.php?key=[APIKEY]&short=https://…); 
  Logger.log(response);
}

标签: google-apps-scripturlfetchhttp-status-code-500

解决方案


推荐阅读