I am stuck with a problem for getting picture URL as a response from Google Plus.
Undermentioned is exactly I need ..
{
"id": "ID",
"name": "NAME",
"given_name": "GiVEN NAME",
"family_name": "FAMILY_NAME",
"link": "https://plus.google.com/ID",
"picture": "https://PHOTO.jpg",
"gender": "GENDER",
"locale": "LOCALE"
}
Till time I am using undermentioned in order to get same. please have a look ..
Using undermentioned in onConnected();
try {
URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo");
//get Access Token with Scopes.PLUS_PROFILE
String sAccessToken;
sAccessToken = GoogleAuthUtil.getToken(MainActivity.this,
mPlusClient.getAccountName() + "",
"oauth2:" + Scopes.PLUS_PROFILE
+ " https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Authorization", "Bearer "
+ sAccessToken);
BufferedReader r = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream(), "UTF-8"));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
line = total.toString();
System.out.println("::::::::::::::::::::::::" + line);
} catch (UserRecoverableAuthException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Intent recover = e.getIntent();
startActivityForResult(recover, REQUEST_AUTHORIZATION);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GoogleAuthException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Output of above mentioned ::
{ "id": "106193796000956371669", "email": "vivek@xyz.com", "verified_email": true, "name": "Vivek Singh", "given_name": "Vivek", "family_name": "Singh", "link": "https://plus.google.com/10619379600095669", "gender": "male", "locale": "en", "hd": "xyz.com"}
Please let know about what I am missing. Any suggestion might be helpful for me.
Thanks!