Profile p = new Profile();
Map<String, String> headerParam = new HashMap<String, String>();
headerParam.put("Authorization", "OAuth " + accessGrant.getKey());
headerParam.put("Content-Type", "application/json");
headerParam.put("Accept", "application/json");
Response serviceResponse;
try {
serviceResponse = authenticationStrategy.executeFeed(profileURL,
MethodType.GET.toString(), null, headerParam, null);
// HttpUtil.doHttpRequest(profileURL, "GET", null, headerParam);
} catch (Exception e) {
throw new SocialAuthException(
"Failed to retrieve the user profile from " + profileURL,
e);
}
String result;
try {
result = serviceResponse
.getResponseBodyAsString(Constants.ENCODING);
LOG.debug("User Profile :" + result);
} catch (Exception e) {
throw new SocialAuthException("Failed to read response from "
+ profileURL, e);
}
try {
JSONObject resp = new JSONObject(result);
if (resp.has("user_id")) {
p.setValidatedId(resp.getString("user_id"));
}
if (resp.has("first_name")) {
p.setFirstName(resp.getString("first_name"));
}
if (resp.has("last_name")) {
p.setLastName(resp.getString("last_name"));
}
p.setDisplayName(resp.getString("display_name"));
p.setEmail(resp.getString("email"));
String locale = resp.getString("locale");
if (locale != null) {
String a[] = locale.split("_");
p.setLanguage(a[0]);
p.setCountry(a[1]);
}
if (resp.has("photos")) {
JSONObject photosResp = resp.getJSONObject("photos");
if (p.getProfileImageURL() == null
|| p.getProfileImageURL().length() <= 0) {
p.setProfileImageURL(photosResp.getString("thumbnail"));
}
}
serviceResponse.close();
p.setProviderId(getProviderId());
userProfile = p;
return p;
} catch (Exception e) {
throw new SocialAuthException(