【问题标题】:Google Script GET request issue谷歌脚本 GET 请求问题
【发布时间】: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


    【解决方案1】:

    好吧,看起来我完全错过了一个很小但非常重要的部分......即使我创建了一个对象来保存方法和标头,但我并没有将它传递给实际的提取! (当您在一天结束时尝试执行 quick 脚本时会发生这种情况)

    所以不是这个

    var fetchResponse = UrlFetchApp.fetch(ENDPOINT_PROJECTS);
    

    我们有这个:

    var fetchResponse = UrlFetchApp.fetch(ENDPOINT_PROJECTS, requestData);
    

    【讨论】:

      猜你喜欢
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 2019-04-05
      相关资源
      最近更新 更多