【发布时间】:2016-07-12 17:00:18
【问题描述】:
我正在尝试获取一个 Google 脚本(在 Google Sheet 上)以从 Float API 检索数据。端点和密钥都很好(经过测试并且在 Postman 上一切正常),但它一直返回 401。
下面是我的代码:
var API_KEY = "{ENTER YOUR KEY HERE}";
var ENDPOINT_PROJECTS = "https://api.float.com/api/v1/projects";
function getProjects() {
var headers = {
"Authorization" : "Bearer " + API_KEY,
};
var requestData = {
"method" : "GET",
"headers": headers,
"muteHttpExceptions": false
};
// Get the data
var fetchResponse = UrlFetchApp.fetch(ENDPOINT_PROJECTS);
var responseCode = fetchResponse.getResponseCode();
if (responseCode == "200") {
var result = JSON.parse(fetchResponse.getContentText());
} else {
ui.alert("Error when attempting to fetch the list of spaces.");
}
}
【问题讨论】:
标签: javascript rest google-apps-script get