I wanna get data from spreadsheet through sheet api.
I create project in GCP and a service account. Then I gave the account the permission of writing the spreadsheet. After that, I downloaded credentials as json.
My application of node is here.
const sheets = google.sheets('v4');
execAPI('[sheet_ID]', 'articles!C5:F8');
async function execAPI(spreadsheetId: string, range: string) {
const key = process.env.private_key === undefined ? undefined : process.env.private_key.replace(/\\n/g, "\n");
const auth = await google.auth.getClient({
credentials: {
client_email: process.env.client_email,
private_key: key,
},
scopes: 'https://www.googleapis.com/auth/spreadsheets.readonly',
});
const apiOptions = {
auth,
spreadsheetId,
range,
};
sheets.spreadsheets.values.get(apiOptions, (err: Error | null, res: GaxiosResponse | undefined | null) => {
console.log(err);
console.log(res);
});
I tried a lot of times, however, only got the error "Invalid grant: account not found"
What should I do?? Please teach me.
There are several reasons for this to occur - see here, the most likely is that you changed your scopes: After doing so, you need to delete your old token file, so that the application will create a new, update token.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With