google-apps-script - 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);
}
解决方案
推荐阅读
- trustpilot - Trustpilot API 查询给定日期范围的评论
- android - 如何在颤振中创建自定义形状小部件
- angular - ngrx 效果说明:@Effect
- php - 我创建了一个聊天应用程序,用于自动获取消息,我使用 setinterval 函数和 ajax 请求来获取数据
- javascript - 重新加载后如何更改同一刀片文件中的表单标签信息
- python - 使用python selenium提取页面源的最快方法是什么
- entity-framework - 使用聚合函数应用 GroupBy 扩展方法的正确方法
- google-bigquery - bigquery 不加载 JSON
- mysql - Sequelize raw select 查询无法访问表
- jestjs - 告诉 jest 处理 Vite 的 "?raw" 语法