0

I've been programming a lot with restfb, but I'm not able to do a counting of comments, only the comments without the answers, the image can better illustrate.enter image description here

Example post comment facebook

My code

Post post = clienteFacebook.fetchObject(idPostagem,
                Post.class,
                Parameter.with("fields", "comments.limit(0).summary(true)"), 
                Parameter.with("filter", "toplevel"));

        System.out.println("Comments count: " + post.getCommentsCount());

Out code comments count

But I need to get only actual comments from the publication, in this example 57 comments.

In https://developers.facebook.com/docs/graph-api/reference/v3.2/object/comments I have some references of filter - toplevel but without success.

I also tested with Comment instead of Post but without success.

How can I get 57 posts in a post?

  • 1
    `total_count` in combination with `filter=toplevel` should get you the count of only those, according to documentation. If it shows this behavior reproducible over several different posts, then file a bug report maybe. (The docs say, _“Note: total_count can be greater than or equal to the actual number of comments returned due to comment privacy or deletion.”_ - but I don’t think that should explain that kind of discrepancy.) – 04FS Mar 14 '19 at 07:56

1 Answers1

0

Please try the following code:

Post post = clienteFacebook.fetchObject(idPostagem,
      Post.class,Parameter.with("fields", "comments.limit(0).summary(1).filter(toplevel)"));

System.out.println("Comments count: " + post.getCommentsCount());

As you can see the filter is part of the fields parameter. But the strange thing is, toplevel is the default filter if no filter is provided. So maybe it is something different.

Maybe you can get in touch with us (RestFB Team) directly, so we can help a bit more in depth ;)

Norbert
  • 1,391
  • 1
  • 8
  • 18