node.js - 使用 api (nodejs) 更新 Google 表格时出错

标签 node.js google-sheets google-api

我正在使用 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/

相关文章:

javascript - 在 Google 表格中输入数据后自动保护单元格/范围

google-sheets - 指向特定工作表的超链接

node.js - 为什么我不能在 Rasspian OS 中运行相同的应用程序?

arrays - nodejs 如何使用多维数组并在其中推送值?

node.js - 使用node js需要从Facebook下载图像

google-apps-script - 如何在 Google Apps 脚本中处理 Google Contacts API 返回的照片字节

java - 尝试访问 google api 时 Java 中的 JSON 错误

node.js - Gulp 安装在项目根目录之外

google-apps-script - 通过 Google Apps 脚本打开 Google 电子表格

java - 允许 App Engine 服务帐户编辑日历