I am trying to obtain all the id, name and image of all friends that have my app installed. When I debug the graph request, the JSONArray is populated with the correct data. But I am not sure how to properly get the data out of the request.
This is my request that does create the correct JSONArray:
GraphRequest friendsRetrievalRequest = GraphRequest.newMyFriendsRequest(
AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONArrayCallback() {
@Override
public void onCompleted(JSONArray jsonArray, GraphResponse response) {
try {
JSONObject jsonObject = response.getJSONObject();
JSONObject summary = jsonObject.getJSONObject("summary");
} catch (Exception e) {
e.printStackTrace();
}
}
});
I have tried:
Bundle params = new Bundle();
params.putString("fields", "id,name,picture");
friendsRetrievalRequest.setParameters(params);
friendsRetrievalRequest.executeAsync();
Intent intent = new Intent(getApplicationContext(), ContactsListActivity.class);
intent.putExtras(params);
startActivity(intent);
But in my ContactsListActivity class I call this:
Bundle inBundle = getIntent().getExtras();
String name = inBundle.get("id").toString();
String surname = inBundle.get("name").toString();
String imageUrl = inBundle.get("picture").toString();
But is all null.
Where am I going wrong? How can I retrieve the array of the friend data obtained within the Graph Request?
EDIT: This is the JSON array I receive, there is one friend which is as expected (I have removed their personal data for privacy, but it is all correct):
[{"id":"their id","name":"their name","picture":{"data":{"is_silhouette":false,"url":"their image url"}}}]