簡體   English   中英

Google Apps腳本和外部API

[英]Google Apps Script and External API

如果我沒有記錯,根據UrlFetch文檔,我應該可以在Google Apps腳本中調用New Basecamp API 我懷疑我的混淆來自格式化GAS錯誤(以及我剛剛開始這一切的事實)。 我用Google搜索了很久。 這就是我所擁有的以及從GAS返回的錯誤:

GAS中的myCode:

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);
}

GAS錯誤消息:

Request failed for https://basecamp.com/2166446/api/v1/projects.json returned code 401.
Server response: HTTP Basic: Access denied. (line 9, file "Code")

我希望這是一個合理的問題,謝謝你的幫助。

使用Utilities.base64Encode HTTP基本身份驗證的正確標頭如下:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM