4

I am trying to retrieve all the posts, the number of likes on each post, the comments on each post and the number of likes of each comment from a particular FB page (https://www.facebook.com/JnuConfessions). I am using RestFB to do this.

While I have managed to get the post content, comments content and comments likes correctly, I am not able to get the number of likes of any post. I use the following code

Page page = facebookClient.fetchObject("jnuConfessions", Page.class);
Connection<Post> myPagePost = facebookClient.fetchConnection(page.getId() + "/posts", Post.class);
for (List<Post> myFeedConnectionPage : myPagePost) {
   for (Post post : myFeedConnectionPage) {
      System.out.println ("Number of likes: " + post.getLikesCount());
   }
}

However for every post, I just get a null value instead of the correct number of likes.

Is there some way to get the number of likes of each post correctly?

ritesh
  • 229
  • 1
  • 5
  • 12

1 Answers1

0

Try this, You should pass the parameters whichever you need.

            for (List<Post> myFeedConnectionPage : myFeed) {
                for (Post post : myFeedConnectionPage) {
                    //JSONObject userPosts = new JSONObject();

                    try {
                        post = facebookClient
                                .fetchObject(
                                        post.getId(),
                                        Post.class,
                                        Parameter
                                                .with("fields",
                                                        "from,actions,message,story,to,likes.limit(0).summary(true),comments.limit(0).summary(true),shares.limit(0).summary(true)"));
                    System.out.println ("Number of likes: " + post.getLikesCount());
                    } catch (Exception e) {
                        e.printStackTrace();

                    }
                }
            }
DevGo
  • 1,045
  • 1
  • 16
  • 42