Max*_*Max 1 javascript google-apps-script pingdom
我尝试按照该示例访问Google Apps脚本中的Pingdom API:https : //developers.google.com/apps-script/external_apis
query = 'credits';
var username = 'foo';
var password = 'bar';
var credentials = username+':'+password;
var url = 'https://'+credentials+'@api.pingdom.com/api/2.0/'+encodeURIComponent(query);
var headers = {
"App-Key": "abcd",
};
var options = {
"method": "get",
"headers": headers,
'validateHttpsCertificates':false
};
Logger.log(url);
var response = UrlFetchApp.fetch(url);
Run Code Online (Sandbox Code Playgroud)
代码执行因以下错误而中断:
意外的错误:https:// foo:bar@api.pingdom.com/api/2.0/credits (第17行,文件“代码”)已关闭
如果我将上述URL复制/粘贴到浏览器中,则可以正常工作(即,我从pingdom API获取“缺少应用程序密钥”,该API会在正确提供用户名和密码的情况下进行确认,否则会收到无效凭据错误)。我尝试encodeURIComponent启用和不启用credentials,都会遇到相同的错误。'muteHttpExceptions':true也没有帮助。
知道什么可能导致错误吗?
似乎在URL中包含登录信息会导致UrlFetchApp错误。请在我们的问题跟踪器中提交错误。同时,将登录信息放在Authorization标头中,它应该可以正常工作。
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Basic ' + Utilities.base64Encode(username + ':' + password)
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2644 次 |
| 最近记录: |