感谢@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"
YOUR Facebook PageID
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));
我尝试捕获,因为在每一行输出数据中,它正在发生变化,例如当您的帖子只有图像并且“故事”、“消息”其中一个返回时,它会返回 full_picture,您可以在浏览器中运行链接并查看输出 json 并根据需要使用它
4- 最后你可以把输出列表放到recyclerView
我希望这会有所帮助:)