0

i have got access token now i want to have refresh token so that i can refresh my access token whenever needed. i used fallowing code but it returned error response

  **OAuthRequest request = new OAuthRequest(Verb.POST, "https://accounts.google.com/o/oauth2/token");
    request.addBodyParameter("grant_type", "refresh_token");
    request.addBodyParameter("refresh_token", "accesstoken string"); 

    request.send();**

any ideas how to get refresh token??????

  • Adding those two lines couldn't cause a problem itself. Just to clarify, in "accesstoken string" you have `accessToken.getToken()`? If yes then check the rest of your code. – lomza Jun 14 '12 at 07:46

3 Answers3

2

You can do that using the following code

OAuthRequest request = new OAuthRequest(Verb.POST, "https://accounts.google.com/o/oauth2/token");
    request.addBodyParameter("grant_type", "refresh_token");
    request.addBodyParameter("refresh_token", accessToken.getToken()); // were accessToken is the Token object you want to refresh.
    request.addBodyParameter("client_id", your clientID);
    request.addBodyParameter("client_secret", your clientSecret);
    Response response = request.send();
Peter T.
  • 8,757
  • 3
  • 34
  • 32
0

A refresh token is obtained in offline scenarios as mentioned in https://developers.google.com/accounts/docs/OAuth2WebServer#offline Make sure access_type is 'offline'

Devashish Mamgain
  • 2,077
  • 1
  • 18
  • 39
0

Actually Scribe doesn't let you to get a refresh token. I had to customize it to make it posible, I did it because i didn't have choice, even the owner(Jerome Leleu) of that library doesn't give maintenance, he is working in a new version called Pac4j.

dmarquina
  • 3,728
  • 1
  • 28
  • 28