Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sheet API (google apis) returns error "'Invalid grant: account not found'

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.

like image 220
hideto Avatar asked Oct 21 '25 16:10

hideto


1 Answers

This error means that the authorization grant or refresh token is invalid

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.

like image 170
ziganotschka Avatar answered Oct 23 '25 06:10

ziganotschka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!