Use {@link GoogleCredential} to access protected resources from the resource server using the{@link TokenResponse} returned by {@link #execute()}. On error, it will instead throw {@link TokenResponseException}.
Sample usage:
static void requestAccessToken() throws IOException { try { GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(), "812741506391.apps.googleusercontent.com", "{client_secret}", "4/P7q7W91a-oMsCeLvIaQm6bTrgtp7", "https://oauth2-login-demo.appspot.com/code") .execute(); System.out.println("Access token: " + response.getAccessToken()); } catch (TokenResponseException e) { if (e.getDetails() != null) { System.err.println("Error: " + e.getDetails().getError()); if (e.getDetails().getErrorDescription() != null) { System.err.println(e.getDetails().getErrorDescription()); } if (e.getDetails().getErrorUri() != null) { System.err.println(e.getDetails().getErrorUri()); } } else { System.err.println(e.getMessage()); } } }
Implementation is not thread-safe.
@since 1.7 @author Yaniv Inbar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|