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??????

1
  • 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. Commented Jun 14, 2012 at 7:46

3 Answers 3

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();
Sign up to request clarification or add additional context in comments.

Comments

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'

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.