Facebook4j:如何获取Facebook的帖子中的喜欢,评论和分享的总数? [英] Facebook4j: How to get total number of likes, comments and shares on a facebook post?

查看:157
本文介绍了Facebook4j:如何获取Facebook的帖子中的喜欢,评论和分享的总数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码:

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

final阅读2 =新的阅读()从( - 1个月)字段(喜欢,id,消息,created_time,从 ).limit(100)。总结();
final ResponseList< Post> feeds2 = facebook.getPosts(viratkohli,reading2); (int i = 0; i< feeds2.size(); i ++){
//获取帖子




Post post1 = feeds2.get(i);
// Get(string)message。
String message = post1.getMessage();
日期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(创建时间:+ 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(******************); (int j = 0; j< feeds1.size(); j ++){
Post post2 = feeds1.get(j);

}


System.out.println(j);
final PagableList< Comment> comments = post2.getComments(); (int k = 0; k< comments.size(); k ++)
{
//获取注释。
评论comment = comments.get(k);
String id2 = comment.getId();
String comm = comment.getMessage();
日期d2 = comment.getCreatedTime();
整数co = comment.getLikeCount();

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

}

System.out.println(~~~~~~~~~~~~~);
}

目前,我可以获得以下信息:



最大100个最近的帖子,25个最近的喜欢,25个最近的评论每个职位(最多40个职位)。



任何帮助克服限制问题将不胜感激

解决方案

这是正确的答案:

  final阅读= new Reading()。summary()。fields(id,message,likes.summary(true),shares,comments.summary(true) ).limit(20).since( -  1个月); 
final ResponseList< Post> feeds = facebook.getPosts(绿色,阅读); (int i = 0; i< feeds.size(); i ++){
//获取帖子


Post post = feeds.get(i);

整数likesCount = post.getLikes()。getSummary()。getTotalCount();
整数sharesCount = post.getSharesCount();
整数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 share 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();


I am trying to retrieve all the essential information regarding facebook posts using facebook4j.

Here is my code:

    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("~~~~~~~~~~~~~");
            }

Currently, I'm able to get the following info:

max. of 100 recent posts, 25 recent likes, 25 recent comments for each post (for max. of 40 posts).

Any help on overcoming the limit issue will be greatly appreciated.

解决方案

Here is the right answer:

    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();

这篇关于Facebook4j:如何获取Facebook的帖子中的喜欢,评论和分享的总数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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