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

DaImTo
  • 88,623
  • 26
  • 153
  • 389
Amir Shahzad
  • 69
  • 1
  • 7

1 Answers1

1

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
  • 525
  • 8
  • 19