我正在使用 googleapis npm 包来更新 google 表格。我正在计算引擎中运行我的nodejs应用程序并尝试使用api更新GSheet,但它抛出一个错误:
The API returned an error: Error: This operation is not supported for this document.
我是工作表的所有者,我可以手动更新它,但在使用 API 更新时遇到错误。
代码:
const {google} = require('googleapis');
google.auth.getClient({
keyFilename: 'keyFilename.json', //service account key json file
scopes: ['https://www.googleapis.com/auth/spreadsheets']
}).then(auth => {
const sheets = google.sheets({version: 'v4', auth});
const data = {};
sheets.spreadsheets.values.append({
spreadsheetId: 'mySpreadSheetId',
range: 'Name of the sheet',
valueInputOption: 'raw',
resource: {
values: data, //Data that i want to update to gsheet
}
}, (err, response) => {
if (err) {
console.log('The API returned an error: ' + err);
reject(err);
} else {
resolve();
}
})
})
最佳答案
就我而言,我将一个 Excel 文件上传到 Google Drive,当我尝试使用 API 更新该工作表时,它不允许我更新。所以,
i created a new sheet in my drive and then i'm able to update it using the api.
关于node.js - 使用 api (nodejs) 更新 Google 表格时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57248425/