26

I am using following code to get the access token for google plus. Is there a way to get the refresh token so that I can access the google API offline from the web server.

String accountName = params[0];
String scopes = "oauth2:profile email";
String token = null;
try {
    token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
} catch (IOException e) {
    Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
    startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
} catch (GoogleAuthException e) {
    Log.e(TAG, e.getMessage());
}
Let'sRefactor
  • 3,303
  • 4
  • 27
  • 43
Anuj
  • 1,160
  • 2
  • 20
  • 40
  • Why are you seeking offline access for an Android app? According to Google's API docs, offline access is for Web apps. Curious what the use case is here. https://developers.google.com/identity/protocols/OAuth2WebServer#offline – fakataha Mar 09 '16 at 02:40
  • @thedarkpassenger IMO, you can read my answer at the following question http://stackoverflow.com/questions/33998335/how-to-get-access-token-after-user-is-signed-in-from-gmail-in-android (at `With a sucessful response, you will have the following info in logcat:`) – BNK Mar 11 '16 at 04:02

1 Answers1

-3

This link very clearly explains the api you need to hit to get token and referesh token for your server side polling.

you would receive a response like so.

{
  "access_token" : "ya29.AHES6ZSuY8f6WFLswSv0HELP2J4cCvFSj-8GiZM0Pr6cgXU",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "1/551G1yXUqgkDGnkfFk6ZbjMLMDIMxo3JFc8lY8CAR-Q"
}

you would do well to read this guide when playing around with tokens in cross platform scenario.

yUdoDis
  • 1,098
  • 6
  • 15