how to use the refreshAccessToken method to generate a new accesstoken in google-api-nodejs-client

后端 未结 2 2004
孤城傲影
孤城傲影 2021-01-20 18:37

I see that this pull request adds a method to refresh the access token using a saved refresh token. It is not clear to me how to use it. I have saved the tokens (including t

2条回答
  •  后悔当初
    2021-01-20 19:29

    I had missed the paragraph on setting credentials on the github readme, so here is some sample code in case anybody else needs it.

    var googleOauth2Client = new OAuth2Client(googleClientId,googleClientSecret, googleCallbackUrl);
    googleOauth2Client.setCredentials({
      refresh_token: saved_refresh_token
    });
    googleOauth2Client.refreshAccessToken(function(err, tokens){
      response.send({
        access_token: tokens.access_token
      });
    });
    

提交回复
热议问题