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
Asked
Active
Viewed 101 times
0
-
Which api are you trying to access? – Linda Lawton - DaImTo Feb 19 '22 at 12:34
-
i want to get refresh token for the authorization in my nodejs app for email verification purpose. Because my old refresh token expires – Amir Shahzad Feb 19 '22 at 12:41
-
1So your trying to access the Gmail api? – Linda Lawton - DaImTo Feb 19 '22 at 14:38
-
Yes, please, you can guide me how to do that. Because when i register user then compiler give me GaxiosError: invalid grant due to expires refresh token – Amir Shahzad Feb 20 '22 at 03:26
-
My apis is that when user register in my app an email sent to the user and then user verify the email with link that is provided in the email then user registered successfully and now user can login – Amir Shahzad Feb 20 '22 at 03:28
-
1If your refresh token has expired you need to request a new one. Run your app again and request consent of the user. – Linda Lawton - DaImTo Feb 20 '22 at 16:43
-
Thanks a lot @DalmTo but request not giving me refresh token – Amir Shahzad Feb 20 '22 at 17:03
-
then please edit your question and include [example] – Linda Lawton - DaImTo Feb 20 '22 at 17:49
1 Answers
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