0

I want to get the refresh token from the google Api's but i don't know how i can get this Please anyone can tell me

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Amir Shahzad
  • 182
  • 2
  • 10

1 Answers1

2

Check this answer on getting Google Refresh Token or check the official documentation on Google Api

oauth2Client.on('tokens', (tokens) => {
  if (tokens.refresh_token) {
    // store the refresh_token in my database!
    console.log(tokens.refresh_token);
  }
  console.log(tokens.access_token);
});

To set the refresh_token at a later time, you can use the setCredentials method:

oauth2Client.setCredentials({
  refresh_token: `STORED_REFRESH_TOKEN`
});

Once the client has a refresh token, access tokens will be acquired and refreshed automatically in the next call to the API.

Note: You should also know that The refresh_token is only returned on the first authorization.

andychukse
  • 520
  • 9
  • 19