I'm using Facebook SDK for android devices. I want all the informations of every post (created time, id, message, imagelink and link). This is my code:
Bundle parameters = new Bundle();
parameters.putString("limit", "100");
final String[]cmb=new String[100];
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/GAMETIMETV/feed",
parameters,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject json = response.getJSONObject();
String[] cmb= new String[100];
try {
JSONArray arrayId = json.getJSONArray("data");
for(int y=0;y<arrayId.length();y++){
cmb[y]=arrayId.getJSONObject(y).getString("id"); //id from json to String array
}
Bundle parametri = new Bundle();
parametri.putString("fields", "link,attachments{media{image}}"); //parameters of the request
for(int i =0;i<cmb.length;i++) {
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + cmb[i].id,
parametri,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
}
}).executeAsync();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}).executeAsync();
This code is heavy, can I have post link and image link without doing another request?
Yes, you can combine this into one API call:
/GAMETIMETV/feed?limit=100&fields=message,created_time,link,attachments{media{image}}
...or like this in your code:
Bundle parameters = new Bundle();
parameters.putString("limit", "100");
parameters.putString("fields", "message,created_time,link,attachments{media{image}}");