简体   繁体   English

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

[英]Fetching all Posts and Comments from a Facebook Page

I'm trying to fetch all the posts and comments from a Facebook Page. 我正在尝试从Facebook页面获取所有帖子和评论。 This works quite good so far using the following FQL: 到目前为止,使用以下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'
}

I'm trying to use the RestFB Library, but I get 我正在尝试使用RestFB库,但是我得到了

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

when I try to execute the query: 当我尝试执行查询时:

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

How can I solve this issue? 我该如何解决这个问题?

Thanks in advance. 提前致谢。

I thought it was a mistake on RestFB side, parsing the result json, because I got several Exceptions and was kind of confused. 我认为这是RestFB方面的一个错误,它解析结果json,因为我遇到了几个异常,并且有点困惑。

The right way to do this is to use the Multiquery Support of RestFB ( Executing Multiqueries with RestFb ) 正确的方法是使用RestFB的多查询支持(使用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);

You have to provide the MultiqueryResults Bean as described in 1 您必须提供如1中所述的MultiqueryResults Bean

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM