好的,我正在使用此google spreadsheet package
的示例代码这是我在index.js中的代码:
const { GoogleSpreadsheet } = require('google-spreadsheet');
// spreadsheet key is the long id in the sheets URL
const doc = new GoogleSpreadsheet('1eSiMGlk0Gkb-HoIExoRDOffUw5ZLyMyMolXEZuHBrsk');
// OR load directly from json file if not in secure environment
await doc.useServiceAccountAuth(require('./privatekey.json'));
await doc.loadInfo(); // loads document properties and worksheets
console.log(doc.title);
await doc.updateProperties({ title: 'renamed doc' });
const sheet = doc.sheetsByIndex[0]; // or use doc.sheetsById[id]
console.log(sheet.title);
console.log(sheet.rowCount);
// adding / removing sheets
const newSheet = await doc.addSheet({ title: 'hot new sheet!' });
await newSheet.delete();
现在我得到了错误
await doc.useServiceAccountAuth(require('./privatekey.json'));
^^^^^
SyntaxError: await is only valid in async function
如果我们转到该函数,则显然是异步的
async useServiceAccountAuth(creds) {
this.jwtClient = new JWT({
email: creds.client_email,
key: creds.private_key,
scopes: GOOGLE_AUTH_SCOPES,
});
await this.renewJwtAuth();
}
我忽略或做错了什么?