I get the token with the following code lines:
Bundle appActivities = new Bundle();
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
"http://schemas.google.com/AddActivity");
String serverClientID = "648976189452-46n3cl4mi4p0vasdr3u1nh87706g0bis.apps.googleusercontent.com";
String scopes = "oauth2:server:client_id:" + serverClientID
+ ":api_scope:" + Scopes.PLUS_LOGIN;
String code = null;
LTDD_1051010005 contex = new LTDD_1051010005();
try {
code = GoogleAuthUtil.getToken(contex, // Context context
plusClient.getAccountName(), // String accountName
scopes, // String scope
appActivities // Bundle bundle
);
} catch (IOException transientEx) {
// network or server error, the call is expected to succeed if you
// try again later.
// Don't attempt to call again immediately - the request is likely
// to
// fail, you'll hit quotas or back-off.
return transientEx.getMessage();
} catch (UserRecoverableAuthException e) {
// Recover
code = null;
} catch (GoogleAuthException authEx) {
// Failure. The call is not expected to ever succeed so it should
// not be
// retried.
return authEx.getMessage();
} catch (Exception e) {
throw new RuntimeException(e);
}
return code;
}
How can i post the code received to my php web server from my Android app? How to verify that token on server and exchange to Google for access token, after that php webserver will return xml and how to andrroid can receive xml data from server immediate.
Thank you!
There's a description on how to pass tokens to your server in the Google+ sign-in documentation.
Basically, you use GoogleAuthUtil.getToken, adding the scope of your server's oauth client id.
String scopes = "oauth2:server:client_id:<SERVER-CLIENT-ID>:api_scope:<SCOPE1> <SCOPE2>";
String code = null;
try {
code = GoogleAuthUtil.getToken(context, account, scopes, null);
...
}
Then you send the received code to your server, which has to exchange it for the server's access and refresh tokens.