如何在Node.js中使用batchUpdate

问题描述 投票:0回答:1

我正在使用以下方法使用 Javascript 访问 Google 电子表格,例如插入一行数据:

const Sheets = require("@googleapis/sheets");
const jwt = new Sheets.auth.JWT(xxemailxx, null, xxprivate keyxx, [...]);
await jwt.authorize();

const sheets = Sheets.sheets("v4");
sheets.spreadsheets.values.append({
    auth: jwt,
    spreadsheetId: "xxxxxxx",
    range: "Sheet1",
    resource: { values: [[1,2,3,4]]}
  }, (err, response) => {
   // ...callback
   }
});

请注意,我在 API 调用中传递了 JWT。这种方法多年来一直很有效。现在我想使用

batchUpdate
附加一行块。我找不到 Node.js 的文档。
@googleapis/sheets
存储库中的链接指向 thisthis,看起来像是用于 Web 服务 API。我尝试了各种排列来传递
requestbody
但没有成功。

使用

batchUpdate
api 的可行方法是什么?是否有关于 Node.js 更具体的
batchUpdate
文档?

google-api google-sheets-api
1个回答
0
投票

推荐:

以下是可用于

batchUpdate
的示例语法:

 sheets.spreadsheets.values.batchUpdate({
  
  "spreadsheetId": 'xxxxxxxx',
  "resource": {
    "valueInputOption": "RAW",
    "data": [
      {
        "range": "A1:C3", //A1 Notation
        "values": [
            ["Hello", "Google", "Sheets"],
            ["Hello", "Google", "Docs"],
            ["Hello", "Google", "Slides"]
        ]
      }
    ]
  }
}, function(error, response){
  if (error) {
    console.log('The API returned an error: ' + error);
    return;
  }
  console.log(response);
});

注意: 无论您将使用哪种身份验证,我相信

responseBody
语法都是相同的。

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.