RestFB没有发表评论 [英] RestFB doesn't give comments of post

查看:70
本文介绍了RestFB没有发表评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 restfb 来以这种方式获取一些帖子以及Facebook页面中每个帖子的每个评论:

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.

它有140条注释,但是toString()方法给了我:

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 ....]

评论的json部分是:

the json part of comment is:

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

count=157

但是如果您现在继续该帖子,它会显示145 ...,并且没有data

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?

推荐答案

我是通过以下方式解决的:

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

这篇关于RestFB没有发表评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆