将参数设置为回调函数 - 大小写:gsheet api

时间:2018-06-09 01:26:50

标签: javascript node.js google-api google-sheets-api asynccallback

node.js googlesheets api example中,一个回调被交给授权程序,在完成所有auth之后执行。

我想将示例打包到一个模块中,并使用它来读取和写入gsheet中的数据。因此,我将启动部分包装到一个正在导出的函数中,并将特定的回调交给授权过程。

示例:

fs.readFile('client_secret.json', (err, content) => {
  if (err) return console.log('Error loading client secret file:', err);
  // Authorize a client with credentials, then call the Google Sheets API.
  authorize(JSON.parse(content), listMajors);
});

裹:

appendLine = line_arr => 
      fs.readFile('client_secret.json', (err, content) => {
        if (err) return console.log('Error loading client secret file:', err);
        // Authorize a client with credentials, then call the Google Sheets API.
        authorize(JSON.parse(content), line_appender);
      });
module.exports = { appendLine }

但是,有什么方法可以使用line_appender回调函数传递line_arr参数,因此它会在回调中使用这些参数值将内容附加到表中吗?

0 个答案:

没有答案