Facebook4j:如何获取facebook帖子上的喜欢、评论和分享的总数?

Facebook4j:如何获取facebook帖子上的喜欢、评论和分享的总数?,facebook,facebook4j,Facebook,Facebook4j,我正在尝试使用facebook4j检索有关facebook帖子的所有基本信息 这是我的密码: final Reading reading1 = new Reading().since("-1 month").limit(38).fields("comments", "likes", "id", "message", "caption", "description", "created_time", "from").summary(); final ResponseList<

我正在尝试使用facebook4j检索有关facebook帖子的所有基本信息

这是我的密码:

    final Reading reading1 = new Reading().since("-1 month").limit(38).fields("comments", "likes", "id", "message", "caption", "description", "created_time", "from").summary(); 
    final ResponseList<Post> feeds1 = facebook.getPosts("viratkohli", reading1);

    final Reading reading2 = new Reading().since("-1 month").fields("likes", "id", "message", "created_time", "from", "story").limit(100).summary(); 
    final ResponseList<Post> feeds2 = facebook.getPosts("viratkohli", reading2);



    for (int i = 0; i < feeds2.size(); i++) {
        // Get post.
        Post post1 = feeds2.get(i);
        // Get (string) message.
        String message = post1.getMessage();
        Date d = post1.getCreatedTime();
        String id = post1.getId();
       PagableList<Like> pl = post1.getLikes();
       String story = post1.getStory();

       System.out.println("post: "+i+": "+message);
       System.out.println("Created time: "+d.toString());
       System.out.println("id: "+id);
       System.out.println("story: "+story);
       System.out.println();
       for(Like like: pl) {
           String like_name = like.getName();
           String like_id = like.getId();

           System.out.println("like name: "+like_name);
           System.out.println("like id: "+like_id);
           System.out.println();
       }
       System.out.println("******************");

    }

        for(int j=0;j<feeds1.size();j++){
            Post post2 = feeds1.get(j);
            System.out.println(j);
            final PagableList<Comment> comments = post2.getComments();
            for(int k=0; k<comments.size(); k++) {
                // Get comment.
                Comment comment = comments.get(k);
                String id2 = comment.getId();
                String comm = comment.getMessage();
                Date d2 = comment.getCreatedTime();
                Integer co = comment.getLikeCount();

                System.out.println("Comment "+k+": "+comm);
                System.out.println("id: "+id2);
                System.out.println("created time: "+d2);

                }

            System.out.println("~~~~~~~~~~~~~");
            }
final Reading reading1=new Reading()。自(“-1个月”)。限制(38)。字段(“评论”、“喜欢”、“id”、“消息”、“标题”、“说明”、“创建时间”、“发件人”)。摘要();
最终响应列表feeds1=facebook.getPosts(“viratkohli”,阅读1);
最终阅读阅读2=新阅读()。自(“-1个月”)。字段(“喜欢”、“id”、“消息”、“创建时间”、“发件人”、“故事”)。限制(100)。摘要();
最终响应列表feeds2=facebook.getPosts(“viratkohli”,reading2);
对于(int i=0;i对于(int j=0;j如果您只想要喜欢的总数,而不想要个人喜欢-则将
limit
设置为0,将
summary
设置为1


以下是正确答案:

    final Reading reading = new Reading().summary().fields("id", "message", "likes.summary(true)", "shares", "comments.summary(true)").limit(20).since("-1 month"); 
    final ResponseList<Post> feeds = facebook.getPosts("green", reading);

    for (int i = 0; i < feeds.size(); i++) {
        // Get post.
        Post post = feeds.get(i);

       Integer likesCount = post.getLikes().getSummary().getTotalCount();
        Integer sharesCount = post.getSharesCount();
       Integer commentsCount = post.getComments().getSummary().getTotalCount();

       if(sharesCount == null)
           sharesCount = 0;
       if(likesCount == null)
           likesCount = 0;
       if(CommentsCount == null)
           commentsCount = 0;
        System.out.println("No. of shares for post "+i+": "+sharesCount);
        System.out.println("No. of likes for post "+i+": "+likesCount);
        System.out.println("No. of comments for post"+i+": "+commentsCount);
        System.out.println();
final Reading Reading=new Reading().summary().fields(“id”、“message”、“likes.summary(true)”、“shares”、“comments.summary(true)”)。限制(20)。自(“-1个月”);
最终回复列表feed=facebook.getPosts(“绿色”,阅读);
对于(int i=0;i
我按照你说的做了。当你将limit设置为0时,你将一无所获。因此我没有使用limit属性(默认情况下,它设置为25)。我调用了ShareScont()方法。我得到了正确的计数值。问题在于likes和comment计数。请从响应JSON数组中查看这些值:fields=likes,shares&summary=true&limit=25 sharesCount=105,likes=PagableListImpl{count=null}。likes计数值为空。您能帮我获取正确的值吗?如果我遗漏了什么,您可以告诉我。提前谢谢。当然,您获取的数据限制为0(当然是likes之一,而不是提要本身),当您将摘要设置为1时:喜欢和评论在帖子的Json数组中有单独的Json数组,其中两者的计数值均为null,摘要均为null。它仅显示喜欢或评论它的人数有限(id和人名)。你能分享一下获取计数的代码片段吗?这会对我有更好的帮助。谢谢。查看我之前评论中的链接-Graph API Explorer中的实时示例演示了它的工作原理。是的。我看到了。这是一个查询。但我需要编程方法。我通过检查数组并进行一些更改来完成。现在我得到了c谢谢你的帮助。