RestFB doesn't give comments of post

纵饮孤独 提交于 2019-12-23 19:39:44

问题


i'm using restfb to fetch some posts and every comment of each posts of a facebook page in this way:

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            
    }

My problem borns when it fetch a post like this.

It has 140 comments but the toString() method gives me:

Post[actions=[...] application=null attribution=null caption=techblr.com comments=Comments[count=157 data=[]] createdTime=Wed Feb 27 14:41:58 CET 2013 ....]

the json part of comment is:

comments=Comments[count=157 data=[]]

count=157

but if you go on that post NOW it says 145... and there is no data!

What could be the problem about that? why it give me different data from real one?


回答1:


I solved in this way:

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;
}


来源:https://stackoverflow.com/questions/15117398/restfb-doesnt-give-comments-of-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!