java - RestFB 不对帖子发表评论

标签 java facebook-graph-api restfb

我正在使用 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... 并且没有数据!

这可能是什么问题?为什么它给我的数据与真实数据不同?

最佳答案

我是这样解决的:

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

关于java - RestFB 不对帖子发表评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15117398/

相关文章:

facebook - 在 Facebook 上获取 friend 的 friend 列表

java - 无法通过restfb为Facebook生成通知

java - 从 Maven 运行特定的独立 ant 目标

java - 如何在 Camel Rest 中验证请求 header

java - 在通过 VPN 运行的 https Web 应用程序上使用 Selenium

php - 发布带有 Facebook 链接的消息时出错

facebook-graph-api - Facebook : Open graph actions not aggregating

java - 如何作为应用程序发布到页面?

java - graph api Restfb - 发布带有链接预览的粉丝专页链接

java - 获取一个按钮,当鼠标悬停在其上时改变颜色