我卡在我的代码这一点上,我已经成功地使用PUT请求调用了Sheets API,但它没有呈现在谷歌表格上。
以下是我的代码,其中我同时使用PUT和GET请求来查看数据是否更改:
background.js
这是我的Google Sheet的截图,数据没有改变。PUT请求的状态为200,看起来数据仍然在A1:B1中是“Hello World”:
这是日志:
你有什么想法,缺少什么吗?
以下是我的代码,其中我同时使用PUT和GET请求来查看数据是否更改:
background.js
chrome.identity.getAuthToken({ 'interactive': true }, getToken);
function getToken(token) {
console.log('this is the token: ', token);
var params = {
"range":"Sheet1!A1:B1",
"majorDimension": "ROWS",
"values": [
["Hi","Crush"]
],
}
let init = {
method: 'PUT',
async: true,
data: params,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
'contentType': 'json',
};
fetch(
"https://sheets.googleapis.com/v4/spreadsheets/1efS6aMlPFqHJJdG8tQw-BNlv9WbA21jQlufsgtMsUmw/values/Sheet1!A1:B1?valueInputOption=USER_ENTERED",
init)
.then((response) => console.log(response))
let request = {
method: 'GET',
async: true,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
'contentType': 'json',
};
fetch(
"https://sheets.googleapis.com/v4/spreadsheets/1efS6aMlPFqHJJdG8tQw-BNlv9WbA21jQlufsgtMsUmw/values/Sheet1!A1:B1",
request)
.then((response) => response.json())
.then(function(data) {
console.log(data)
});
}
这是我的Google Sheet的截图,数据没有改变。PUT请求的状态为200,看起来数据仍然在A1:B1中是“Hello World”:
![enter image description here](https://istack.dev59.com/ZCN3F.webp)
![enter image description here](https://istack.dev59.com/Xa3Pp.webp)
data: JSON.stringify(params)
,但文本仍未更改。我已在请求中删除了'contentType': 'json'。 - Jessica Rodriguez