Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js GoogleSheetAPI节点_Node.js_Google Sheets_Google Sheets Api - Fatal编程技术网

Node.js GoogleSheetAPI节点

Node.js GoogleSheetAPI节点,node.js,google-sheets,google-sheets-api,Node.js,Google Sheets,Google Sheets Api,我有数据在谷歌表的第一列是id和每个id都有关联的数据。我想通过使用特定的id号在一次搜索中获得多行。为此,我想使用batchGetByDataFilter,但我不知道如何使用,因为我是google sheet的新手。请帮帮我。 异步函数gsrun(cl){ 我相信你的目标如下 您希望通过使用Node.js搜索列“A”处的ID来检索行 在脚本中,您已经完成了从电子表格中检索值的授权过程 对于这个问题,这个答案如何 在这种情况下,我建议使用查询语言而不是batchGetByDataFilter

我有数据在谷歌表的第一列是id和每个id都有关联的数据。我想通过使用特定的id号在一次搜索中获得多行。为此,我想使用batchGetByDataFilter,但我不知道如何使用,因为我是google sheet的新手。请帮帮我。 异步函数gsrun(cl){


我相信你的目标如下

  • 您希望通过使用Node.js搜索列“A”处的ID来检索行
  • 在脚本中,您已经完成了从电子表格中检索值的授权过程
对于这个问题,这个答案如何

在这种情况下,我建议使用查询语言而不是
batchGetByDataFilter
。这样,查询语言可以直接检索搜索到的行。我认为这种方法更简单。示例脚本如下

示例脚本: 在这个脚本中,访问令牌是从
const gsapi=google.sheets({version:'v4',auth:cl})
cl
使用的。在这种情况下,使用
request
csv parse
模块

const request = require("request");
const csvParse = require("csv-parse");

const spreadsheetId = "###";  // Please set the Spreadsheet ID.
const sheetId = "###";  // Please set the sheet ID.
const searchId = "###";  // Please set the search ID.

cl.getRequestHeaders().then((authorization) => {
  const query = `select * where A='${searchId}'`;
  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;
    }
    csvParse(result, {}, (err, ar) => console.log(ar));
  });
});
参考资料:

我可以问一下您的情况吗?1.为了在Sheets API中使用
batchGetByDataFilter
,需要将元数据设置到电子表格中。如何?2.我可以问一下您期望的结果值吗?3.您的
gsapi
是否可以用于从电子表格中检索值?即,您已经确认您的脚本的授权过程已经完成了?感谢您的响应。gsapi可以从google sheet检索数据,但它正在收集整行和整列数据。但我只想接收特定数据。我有5列,数据中有很多行。第一行是id ex.101,关联行包含数据。我只想要g通过id获取数据。我第一次使用google sheet不知道如何使用元数据。感谢您的回复。从您的回复中,我可以确认您已经使用Sheets API完成了从电子表格检索值的授权。但是从
中,我只想通过id获取数据
,我无法理解您体验的结果值t、 通过从列“A”中搜索ID,您希望检索哪些值?我想通过正确理解您的目标,我可能能够提出解决方案。感谢您的快速响应。我在第一行有标题名称的数据:ID、产品、价格、数量。在第二行我有数据101、lime、45、1,以及直到100行。我想使用ID获取数据行谢谢您的回复。在您的情况下,您要通过从列“A”中搜索ID来检索行.我的理解正确吗?@brownveg欢迎。谢谢你让我知道。我很高兴你的问题得到了解决。如果你的问题得到了解决,请按下“接受”按钮。与你有相同问题的其他人也可以将你的问题作为可以解决的问题。我认为你的问题和解决方案将对他们有用。我如果您找不到按钮,请随时告诉我。抱歉,响应延迟,请告诉我需要安装的按钮press@brownveg谢谢您的回复。给您带来的不便我深表歉意。您可以在@brownveg上查看如何接受您的回复。您能理解我的回复吗?
const request = require("request");
const csvParse = require("csv-parse");

const spreadsheetId = "###";  // Please set the Spreadsheet ID.
const sheetId = "###";  // Please set the sheet ID.
const searchId = "###";  // Please set the search ID.

cl.getRequestHeaders().then((authorization) => {
  const query = `select * where A='${searchId}'`;
  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;
    }
    csvParse(result, {}, (err, ar) => console.log(ar));
  });
});