Parsing the response from Facebook FQL and displaying it in proper format
android, facebook, facebook-fql
Solution
public void onCompleted(Response response) {
GraphObject graphObject = response.getGraphObject();
String s = textViewResults.getText().toString();
if (graphObject != null) {
JSONObject jsonObject = graphObject.getInnerJSONObject();
try {
JSONArray array = jsonObject.getJSONArray("data");
for (int i = 0; i < array.length(); i++) {
JSONObject object = (JSONObject) array.get(i);
Log.d(TAG, "id = "+object.get("id"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
textViewResults.setText(s);
}
}));
}
request.executeAsync();
Problem
How to get list of friends using my app in an activity using Facebook API?Currently developing an app with the use of Facebook API to show list of friends to the user whom have installed my app.I have tried using Graph API explorer like "me/friends?fields=name,likes,installed" but i want to know how get the desired result in my Android App Activity. Now i am able to get this using FQL query: ``` {Response:responseCode:200, graphObject:GraphObject{graphObjectClass=GrahObject,state= { "data": [ { "uid": xxxx98471, "name": "ABC" }, { "uid": xxx425672424, "name": "XYZ" } ] },error:null, isFromCache:false} ``` So how to format this output and display it in proper manner as: Name: ABC Name: XYZ in listview or so... I have tried using: ``` public void onCompleted(Response response) { GraphObject graphObject = response.getGraphObject(); String s = textViewResults.getText().toString(); if (graphObject != null) { if (graphObject.getProperty("id") != null) { s = s + String.format("%s: %s\n", graphObject.getProperty("id"), graphObject.getProperty("name")); } } textViewResults.setText(s); } })); } request.executeAsync(); ``` I am getting "null" in the result. So now can anybody tell me how to parse this type of response.Any help would be highly appreciated.