0

Okay so I'm using the example code of this google spreadsheet package

So this is my code in 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();

Now I get the error

await doc.useServiceAccountAuth(require('./privatekey.json'));
^^^^^
SyntaxError: await is only valid in async function

If we go to the function, it's clearly async

async useServiceAccountAuth(creds) {
    this.jwtClient = new JWT({
      email: creds.client_email,
      key: creds.private_key,
      scopes: GOOGLE_AUTH_SCOPES,
    });
    await this.renewJwtAuth();
  }

What am I overlooking or doing wrong?

0 Answers0