问题描述
var values = [
[
'value1','value2','value3'
]
];
var body = {
values: values
};
gapi.client.sheets.spreadsheets.values.update({
spreadsheetId: '1Lofhq9R7X5wzGvO7fMViN8D8q1W3fiNxO5jjP7XL_s0',
range: 'Sheet1!A1:A4',
valueInputOption:'RAW',
resource: body
}).then((response) => {
var result = response.result;
console.log(`${result.updatedCells} cells updated.`);
});
显示错误
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"valueInputOption\": Cannot bind query parameter. Field 'valueInputOption' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"valueInputOption\": Cannot bind query parameter. Field 'valueInputOption' could not be found in request message."
}
]
}
]
}
}
我已更改了Google电子表格的访问设置,以允许任何拥有该链接的人查看和编辑它。只有在我尝试写入电子表格时才会出现此错误,我可以使用其他功能阅读电子表格。
I've changed access settings of the google spreadsheet to allow anyone with it's link to view and edit it. This error is arising only when I'm trying to write into the spreadsheet, I'm able to read a spreadsheet using other functions.
推荐答案
我错误地指定了API所需的授权范围(在调用更新函数之前)。
使用
https://www.googleapis.com/auth/spreadsheets
而不是
https://www.googleapis.com/auth/spreadsheets.readonly
I had specified the authorization scope required by the API incorrectly(before the update function was called).Error got fixed after usinghttps://www.googleapis.com/auth/spreadsheets
instead ofhttps://www.googleapis.com/auth/spreadsheets.readonly
这篇关于使用Google API“写入”Google电子表格时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!