我使用Facebook SDK安卓设备。我想要每个帖子的所有信息(创建时间,id,消息,imagelink和链接)。这是我的代码:
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();
此代码很重,我可以在没有其他请求的情况下发布链接和图像链接吗?
答案 0 :(得分:2)
是的,您可以将其合并为一个API调用:
/GAMETIMETV/feed?limit=100&fields=message,created_time,link,attachments{media{image}}
...或者在你的代码中这样:
Bundle parameters = new Bundle();
parameters.putString("limit", "100");
parameters.putString("fields", "message,created_time,link,attachments{media{image}}");