【发布时间】:2014-03-07 06:51:16
【问题描述】:
我构建了通过外部 API 获取数据的 Google Apps 脚本应用程序。
运行此应用程序时,我得到了预期的结果,没有任何错误。但是,当通过时间驱动触发器运行它时,我得到了错误。有谁知道为什么会出现这个错误?
代码:
function triggerFetchTest() {
// get token
try {
var id = "my_id",
password = "my_password",
tokenUrl = ("https://api.example.jp/v1/foo/auth/get_token?id=" + id
+ "&password=" + password),
tokenResponse = UrlFetchApp.fetch(tokenUrl);
var token = JSON.parse(tokenResponse.getContentText())["token"];
Logger.log(token);
}
catch(e) {
Logger.log(e);
}
}
另外:
- 如果我在脚本编辑器中按“运行”按钮,我可以获得正确的响应。
- 设置触发器没有任何问题。
- 我尝试设置“muteHttpExceptions”:true,但出现错误。
- External APIs Doc 下面的代码即使被触发也是可以的。
var url = 'https://gdata.youtube.com/feeds/api/videos?' + 'q=滑板+狗' + '&开始索引=21' + '&max-results=10' +'&v=2'; var response = UrlFetchApp.fetch(url); Logger.log(响应);
我想为此应用设置每日计时器并自动生成报告。请给我一些想法。
*这篇文章是我在 Stackoverflow 上的第一篇文章,而且我通常不会说英语,所以如果你看不懂我上面的英语,我很抱歉......
【问题讨论】:
-
究竟是什么错误?