使用 node.js 查询 google sheet 和 return 行

using node.js to query a google sheet and return row

所以我正在构建一个不和谐的机器人,它像数据库一样使用 google sheets。我希望用户能够输入具有唯一 ID 的命令,每一行都将具有该 ID,然后 return 所述行的所有值和存储而不是作为变量。稍后将在其他地方使用。

用户运行的命令是“>读取(UNIQUEID)”,然后我希望机器人回复“(UNIQUEID)已找到”如果找到并且“(UNIQUEID ) 找不到"。

然后用户将使用第二个命令“>上传”将整行上传到新的跨页sheet。

我有信心我可以自己完成>上传代码,但是对于我来说,我不知道如何使用 google sheets api 进行查询。对于下面的一些参考,我附上了我想阅读的 sheet 的图像。

Google Sheet To Read From

google sheet 中还会有更多信息,但出于测试目的,我只保留了一个条目。

编辑 1:我一直在研究 Google 可视化 API,我做了一些研究,但我不确定这是否真的适用于 sheets?从一些文档来看,它似乎是用于图表的..

我从另一个 Whosebug 问题中找到了问题的答案,@Tanaike 也回答了这个问题。下面是代码。

const request = require("request");
        const csvParse = require("csv-parse");
        const spreadsheetId = "DOCUMENT_ID";  // Document ID
        const sheetId = "SHEET_ID";  // sheet ID
        const searchId = `${QUERY}`;  // what im searching for
        
        spread.getRequestHeaders().then((authorization) => {
          const query = `select * where K='${searchId}'`; // K can be changed to the col the data is on
          const url = `https://docs.google.com/spreadsheets/d/${spreadsheetId}/gviz/tq?tqx=out:csv&gid=${sheetId}&tq=${encodeURI(query)}`;
          let options = {
            url: url,
            method: "GET",
            headers: authorization,
          };
          request(options, (err, res, result) => {
            if (err) {
              console.log(err);
              return;
            }
            if (result === ("")) {
            return message.channel.send(`\`${QUERY}\` Did not match to any records.`); //ID didnt match
            } else {
            message.channel.send(`\`${QUERY}\` has been matched with; ${result}`) //confirms ID has matched
            csvParse(result, {}, (err, ar) => console.log(ar)) // console logs results
    ````