我正在提取Facebook页面的帖子详细信息。我提取了特定页面的json,现在我必须得到该页面所有帖子的id。我怎么能用facebook4j来做呢。
private static String readpage(Reader rd) throws IOException
{
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1)
{
sb.append((char) cp);
}
return sb.toString();
}
public static JSONObject readurl(String url) throws IOException, JSONException
{
InputStream is = new URL(url).openStream();
try
{
BufferedReader rd = new BufferedReader(new InputStreamReader
(is, Charset.forName("UTF-8")));
String jsonText = readpage(rd);
JSONObject json = new JSONObject(jsonText);
return json;
}
finally
{
is.close();
}
}
public static void main(String[] args) throws
IOException, JSONException, FacebookException
{
JSONObject json = readurl("https://graph.facebook.com/"+s);
}
答案 0 :(得分:1)
您可以参考以下代码获取特定页面的所有帖子相关信息:
ResponseList<Post> results = facebook.getPosts(searchPost);
String userId = "";
for (Post post : results) {
obj.put("Post Id", post.getId());
obj.put("Post message", post.getMessage());
obj.put("No of likes on Post", post.getLikes().size());
obj.put("Post owner name:", post.getFrom().getName());
objArray = new JSONArray();
其中 obj 是一个JSON对象。
PS:我使用的是eclipse kepler和facebook4j-core-2.0.2