Response serviceResponse;
try {
serviceResponse = authenticationStrategy.executeFeed(CONTACTS_URL);
} catch (Exception e) {
throw new SocialAuthException("Error while getting contacts from "
+ CONTACTS_URL, e);
}
if (serviceResponse.getStatus() != 200) {
throw new SocialAuthException("Error while getting contacts from "
+ CONTACTS_URL + "Status : " + serviceResponse.getStatus());
}
String respStr;
try {
respStr = serviceResponse
.getResponseBodyAsString(Constants.ENCODING);
} catch (Exception exc) {
throw new SocialAuthException("Failed to read response from "
+ CONTACTS_URL, exc);
}
LOG.debug("User Contacts list in JSON " + respStr);
JSONObject resp = new JSONObject(respStr);
List<Contact> plist = new ArrayList<Contact>();
JSONArray items = new JSONArray();
if (resp.has("response")) {
JSONObject robj = resp.getJSONObject("response");
if (robj.has("friends")) {
JSONObject fobj = robj.getJSONObject("friends");
if (fobj.has("items")) {
items = fobj.getJSONArray("items");
}
} else {
throw new SocialAuthException(
"Failed to parse the user profile json : " + respStr);
}
} else {
throw new SocialAuthException(
"Failed to parse the user profile json : " + respStr);
}
LOG.debug("Contacts Found : " + items.length());
for (int i = 0; i < items.length(); i++) {
JSONObject obj = items.getJSONObject(i);