我正在使用restfb以这种方式获取Facebook页面每个帖子的一些帖子和每条评论:
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
Connection<Post> pagePosts = facebookClient.fetchConnection("iPhone.page/feed", Post.class);
for (List<Post> posts : pagePosts)
for (Post post : posts){
for(Comment comment: post.getComments().getData()){
//get number of likes of comment
}
String message = post.getMessage();
String id = post.getId();
long timestamp = post.getCreatedTime().getTime()/1000;
//store info
}
我在提取this等帖子时遇到了问题。
它有140条评论,但toString()
方法给了我:
Post[actions=[...] application=null attribution=null caption=techblr.com comments=Comments[count=157 data=[]] createdTime=Wed Feb 27 14:41:58 CET 2013 ....]
评论的json部分是:
comments=Comments[count=157 data=[]]
count=157
但是,如果你现在继续该帖子,它会说145 ...而且没有data
!
这可能是什么问题?为什么它给我不同的真实数据?
答案 0 :(得分:5)
我这样解决了:
private static List<FBComment> getCommentFromPost(FacebookClient client, String post_id){
List<String> comments = new ArrayList<FBComment>();
Connection<Comment> allComments = client.fetchConnection(post_id+"/comments", Comment.class);
for(List<Comment> postcomments : allComments){
for (Comment comment : postcomments){
long likes = comment.getLikeCount()==null?(comment.getLikes()==null?0:comment.getLikes()):comment.getLikeCount();
comments.add(comment.getMessage()+" - "+likes);
}
}
return comments;
}