【问题标题】:404 Error on Google Sheets API from HTTP Request来自 HTTP 请求的 Google Sheets API 404 错误
【发布时间】:2018-01-05 22:38:54
【问题描述】:

我正在尝试使用 HTML POST 请求将一些数据附加到 Google 表格电子表格。我在解决发送请求时遇到的 404 错误时遇到了一些困难。我的请求代码如下所示:

var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
  if (httpRequest.readyState == XMLHttpRequest.DONE) {
    alert(httpRequest.status);
  }
}

var params = {
  "values": [
     [
       "value1",
       "value2"
     ]
  ]
}

httpRequest.open('POST', 'https://sheets.googleapis.com/v4/spreadsheets/' + spreadsheetID + 'values/Sheet1!B2:L2:append', true)
httpRequest.setRequestHeader('Authorization', 'Bearer ' + accessToken);
httpRequest.setRequestHeader('Content-Type', 'application/json');
httpRequest.send(JSON.stringify(params));

我已经获得了访问令牌中的必要权限,因为我能够创建工作表,但我认为我的网址可能存在问题。提前致谢!

【问题讨论】:

    标签: google-sheets google-api httprequest


    【解决方案1】:

    来自文档sheets.append

    https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/{range}:append

    我认为您在值之前缺少 /

    'https://sheets.googleapis.com/v4/spreadsheets/' + spreadsheetID + '/values/Sheet1!B2:L2:append', true)
    

    尝试使用文档页面 here 上的 Try this api 对其进行测试

    【讨论】:

      猜你喜欢
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多