从Facebook页面获取所有帖子和评论

时间:2013-02-12 22:57:33

标签: java facebook facebook-graph-api facebook-fql restfb

我正在尝试从Facebook页面获取所有帖子和评论。 到目前为止,这使用以下FQL非常好:

{'all_posts':
'SELECT created_time, post_id, actor_id, message, description, comments FROM stream 
   WHERE source_id=PAGE_ID ORDER BY created_time', 
'comments':
   'SELECT id, fromid, post_fbid, text, time, post_id FROM comment WHERE post_id   
    IN (SELECT post_id FROM #all_posts) ORDER BY post_id'
}

我正在尝试使用RestFB库,但我得到了

com.restfb.exception.FacebookResponseStatusException: Received Facebook error response 
(code 601): Parser error: unexpected '{' at position 0.

当我尝试执行查询时:

List<JsonObject> queryResults = facebookClient.executeQuery(query, JsonObject.class);

我该如何解决这个问题?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我认为在RestFB方面是一个错误,解析结果json,因为我得到了几个例外并且有点混乱。

正确的方法是使用RestFB的多重查询支持(Executing Multiqueries with RestFb

Map<String, String> queries = new HashMap<String, String>();
queries.put("all_posts", "select created_time, post_id, actor_id, message, description, comments from stream where source_id=279947942083512 ORDER BY created_time");
queries.put("comments", "SELECT fromid, username, text, time, post_id FROM comment WHERE post_id in (SELECT post_id FROM #all_posts) ORDER BY post_id");

MultiqueryResults queryResults = facebookClient.executeMultiquery(queries, MultiqueryResults.class);

您必须按照1

中的说明提供MultiqueryResults Bean