【发布时间】:2019-05-10 17:51:58
【问题描述】:
我对 REST 的概念非常陌生,我一直在尝试使用 Google 的表格、云端硬盘和课堂 API。我已经能够提取课堂花名册数据,但我一生都无法弄清楚如何使用 parseError 解决这个问题,并且谷歌搜索数小时也没有帮助。
let init = {
method: "POST",
async: true,
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
body: {
"mimeType": "application/vnd.google-apps.spreadsheet"
},
"contentType": "application/json"
};
fetch('https://www.googleapis.com/drive/v3/files?key='+apicall, init)
.then((response) => response.json())
.then(function(data) {
console.log(data);
console.log(init);
});
控制台日志是我可以查看数据的,这显然不会出现在最终项目中,但是每次我发送请求时,它都会抛出错误 400 parseError,这是Google clearly tells me is a Content-Type error,但我指定了它是 JSON,所以我有点困惑。非常感谢任何帮助!
【问题讨论】:
标签: json rest google-api request content-type