简体   繁体   中英

How to read a single google sheets cell value in javascript

I am trying to pull just one cell value from a google sheet using javascript and the google sheets API, and I am using the below code, but I keep getting the below error which I can't understand because I am using the spreadsheet id and range.

throw new Error('Missing required parameters: ' + missingParams.join(', ')); Error: Missing required parameters: spreadsheetId, range

const auth = new google.auth.GoogleAuth({
            keyFile: "sheets-credentials.json",
            scopes: "https://www.googleapis.com/auth/spreadsheets",
        });
const client = await auth.getClient();
const googleSheets = google.sheets({ version: "v4", auth: client });
const spreadsheetId = "asheetid";
googleSheets.spreadsheets.values.get(spreadsheetId, `Sheet1!D1`)

In your script, please modify as follows.

From:

googleSheets.spreadsheets.values.get(spreadsheetId, `Sheet1!D1`)

To:

googleSheets.spreadsheets.values.get({spreadsheetId, range: `Sheet1!D1`});

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM