Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.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应用程序脚本和外部API_Api_Https_Google Apps Script_Basecamp - Fatal编程技术网

Google应用程序脚本和外部API

Google应用程序脚本和外部API,api,https,google-apps-script,basecamp,Api,Https,Google Apps Script,Basecamp,如果我没有弄错的话,按照我的建议,我应该能够从谷歌应用程序脚本中调用。我怀疑我的困惑来自格式错误(以及我刚刚开始这一切的事实)。我已经在谷歌上搜索了很久了。这就是我所得到的和我从气体中得到的错误: 气体中的霉菌代码: function myFunction() { var url = "https://basecamp.com/******/api/v1/projects.json"; var headers = { "contentType": "ap

如果我没有弄错的话,按照我的建议,我应该能够从谷歌应用程序脚本中调用。我怀疑我的困惑来自格式错误(以及我刚刚开始这一切的事实)。我已经在谷歌上搜索了很久了。这就是我所得到的和我从气体中得到的错误:

气体中的霉菌代码:

function myFunction() {
  var url = "https://basecamp.com/******/api/v1/projects.json";
  var headers = {
                 "contentType": "application/json",
                 "headers":{ "User-Agent": "MY_APP_NAME",
                            "username:password" : "user:pass"},
                 "validateHttpsCertificates" :false
                 };

var response = UrlFetchApp.fetch(url, headers);
var text = response.getResponseCode();
Logger.log(text);
}
气体错误信息:

Request failed for https://basecamp.com/2166446/api/v1/projects.json returned code 401.
Server response: HTTP Basic: Access denied. (line 9, file "Code")
我希望这是一个合理的问题,谢谢你的帮助

的正确标题(使用)如下所示:

"headers": {
    "User-Agent": "MY_APP_NAME (App URL/your email address)",
    "Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)
},

太神了谢谢作品great@mat10112:信息到处都是。我从您最初发布的API链接开始,其中提到可以使用HTTP基本身份验证。因为它比OAuth更容易使用,所以我去Wikipedia仔细检查用于HTTP基本身份验证的确切头。然后我查看了文档页面,因为我知道他们有一些内置的实用程序。然后我把它放在一起。好的,从现在开始我会搜索得更好。我是新来的,所以当事情不那么熟悉的时候很难导航。再次感谢你的帮助。如果可以,我会投票。