在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参数,因此它会在回调中使用这些参数值将内容附加到表中吗?