From 90f40842600e0a192d71227554b51dd1a6da8c7c Mon Sep 17 00:00:00 2001 From: Pierfrancesco Soffritti Date: Mon, 13 Jun 2016 09:32:20 +0200 Subject: [PATCH] Update README.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fc528e4..460ddae 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ Authenticator authenticator = new Authenticator(activity, new SharedPreferencesC OAUTH_URL, scopes, REDIRECT_URI, RESPONSE_TYPE, CLIENT_ID, ACCESS_TYPE, TOKEN_URL, CLIENT_SECRET); ``` Use the method `getAccessToken()` to get an access token.
-If no access token has been previously requested, this method automatically asks the user for permissions and then gets an access token from the server. -If the access token has expired, this method automatically asks for a new one. +If no access token has been previously requested, this method automatically asks the user for permissions and then gets an access token from the server.
+If the access token has expired, this method automatically asks for a new one.
See the documentation of the method for more info. Once obtained, you can use the access token to make authorized API calls. @@ -53,5 +53,19 @@ headers.setAuthorization("Bearer " + accessToken); Plus plus = new Plus.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), request -> request.setHeaders(headers)) .setApplicationName("AppName") .build(); + +try { + Plus.People.Get request = plus.people().get("me"); + request.setFields("displayName"); + + request.setKey("yourAPIKey"); + + Person person = request.execute(); + String name = person.getDisplayName(); +} catch (Exception e) { + authenticator.handleException(e); +} ``` +remember to always call `authenticator.handleException(e);` when you make an API call using this access token. This is necessary in order to handle the case in which the user revokes the authorization, but the access token hasn't expired yet. + You can see the sample app for a working implementation with the Google+ API and the YouTube Data API.