我需要一些帮助吗? 我开发了一个应用程序,查看最近20个Facebook页面提要(带图像的帖子,如果存在)我使用图表 (https://graph.facebook.com/229161663845327/feed?access_token=266494063684850|799f6a5b3246ceeecae7e95af945da24&limit=20)但它给了我一个没有它的图像的文字结果我怎么能显示&获取每个帖子的文本和图像,而无需在应用程序中登录Facebook
答案 0 :(得分:2)
我终于解决了这个问题,感谢@sunil晴天你的评论很有帮助。 我用这个api" https://graph.facebook.com/229161663845327/feed?fields=full_picture,id,story,created_time,message&access_token=266494063684850|799f6a5b3246ceeecae7e95af945da24&limit=20"
答案 1 :(得分:2)
感谢@sunil sunny,我解决了这个问题,并且无需在您的应用中登录facebook即可正常工作, 请按照以下步骤操作:
1-在Facebook开发者网站中,创建新项目并在下一步中使用access_token 转到graph api,然后点击“Graph API Explorer”按钮 2-使用volley或http请求或您喜欢此链接的内容向此链接发出请求
String FACEBOOKURL="https://graph.facebook.com/YOUR Facebook PageID/feed?"
+"fields=id,story,created_time,message,full_picture&access_token=/* put your access token that you take from step 1*/&limit=15"
3-从请求中检索数据,因为字符串可以像这样转换
JSONObject dataObj = null;
Log.i("// url", URL.FACEBOOKURL);
try {
String story = "";
String message = "";
String created_time = "";
String image = "";
String id = "";
dataObj = new JSONObject(response);
JSONArray jdata = dataObj.getJSONArray("data");
JSONObject jpaging = dataObj.getJSONObject("paging");
final String previous = jpaging.getString("previous");
final String next = jpaging.getString("next");
for (int i = 0; i < jdata.length(); i++) {
JSONObject jsonObject = jdata.getJSONObject(i);
try {
message = jsonObject.getString("message");
story = "";
} catch (JSONException e) {
story = jsonObject.getString("story");
Log.i("//story", story);
}
created_time = jsonObject.getString("created_time");
try {
image = jsonObject.getString("full_picture");
} catch (JSONException e) {
image = "";
}
id = jsonObject.getString("id");
String[] parts = id.split("_");
String pageId = parts[0];
final String postId = parts[1];
Log.i("---//message", postId);
Log.i("---//image", image);
fbDataList.add(new FbData(postId, message, story, created_time, image));
我试试catch因为在输出数据的每一行中,当你的帖子只有图像而且“故事”,“消息”中的一个返回时,它正在改变如full_picture它的返回,你可以在浏览器中运行链接并查看输出json并根据需要使用它
4-最后,您可以将输出列表放入recyclerView
我希望这会有所帮助:)