【发布时间】:2021-10-10 15:01:28
【问题描述】:
所以我尝试使用电子表格.values.get 从我的谷歌表格中获取行,值的输出看起来像这样。
[
'Name',
'Date',
'Rate',
'Description',
'Seasons'
],
[
'2Name',
'2Date',
'2Rate',
'2Description',
'2Seasons'
],
我认为它是数组中的数组,我的编码不太好,我想将名称、日期、速率、desc 和季节放入变量中,通过 discord.js 将其发布为嵌入并重复直到数组结束
这是完整的代码:
const {google} = require('googleapis')
const auth = new google.auth.GoogleAuth({
keyFile: 'keys.json',
scopes: 'https://www.googleapis.com/auth/spreadsheets',
});
GetValues();
async function GetValues() {
const googleClient = await auth.getClient();
const googleSheets = google.sheets({version: 'v4', auth: googleClient});
const spreadsheetId = 'IDHere';
try {
const response = (await googleSheets.spreadsheets.values.get({
auth,
spreadsheetId,
range: 'A2:E',
valueRenderOption: 'FORMATTED_VALUE',
dateTimeRenderOption: 'SERIAL_NUMBER'
})).data;
console.log(response.values);
//return(JSON.stringify(response, null, 2));
} catch (err) {
console.error(err);
}
};
如果您需要更多信息,请在 cmets 中询问,谢谢
【问题讨论】:
标签: node.js arrays google-sheets discord.js