How to get comments by given user in Facebook Graph API Can we get list of comments made by given user

0 votes

How to  get comments by given user in Facebook Graph API?In Facebook Graph API, can we get list of comments made by given user?

I haven't found any direct way to get lists of comments. So, I tried to find them through my feed, but it's returning all feed posts. Can we filter other posts where I have not commented?

I tried various queries as below, but could not get exactly what I need.

/me/feed?fields=comments?fields=from?name="Niraj dey",message

/me/feed?fields=comments.fields(from.name("Niraj dey"),message)

I need either (1) list of all comments by me or else (2) lists of posts which I have commented on, filtering out all other posts. How can we do this? (Finally I'll be using Java api to do the same.)

May 7, 2020 in Java by kartik
• 37,520 points

edited May 8, 2020 by kartik 12,656 views

1 answer to this question.

0 votes

Hii kartik,

  • You can get the list of comments of an user by using spring supported Facebook API.
  • To access any information of an user you have to pass access token of that particular user. To get list of comments, you have to create FaceBookTemplate object by passing access token and by using that get FeedOperations object.
  •  By using FeedOperations object you can get feed,posts,status,links and so on. Get the list of post and iterate each and every post and get all the comments of the post which was made by you on that post.

Example code:-

    FaceBook faceBook = new  FaceBookTemplate(accessToken);
    FeedOperations feeds=faceBook.feedOperations();
    List<Post> posts=feeds.getPosts();
    List<Comment> comments=new ArrayList<>();

    for(Post post:posts){
        List<Comment> commentsList = post.getComments();

        for(Comment comment:commentsList){
                comments.add(comment);
        }
    }

Thank You!!

answered May 7, 2020 by Niroj
• 82,880 points

Related Questions In Java

0 votes
2 answers

How can I invoke a method when the method name is in the form of a given string?

You could probably use method invocation from reflection: Class<?> ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 59,230 points
3,048 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,920 points
1,891 views
0 votes
1 answer

How can we get file extension in Java?

To get the file extension, we can ...READ MORE

answered May 8, 2018 in Java by Parth
• 4,640 points
2,981 views
0 votes
1 answer

How to get the number of digits in an int?

You can find out the length of ...READ MORE

answered May 14, 2018 in Java by Akrati
• 3,190 points
934 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,396 views
0 votes
1 answer
+1 vote
1 answer

if i given invalid data how to get alert in selenium using java

Hello, Here is some of the method you ...READ MORE

answered Jul 20, 2020 in Java by Niroj
• 82,880 points
1,206 views
0 votes
1 answer

How can I set JFrame to appear centered, regardless of monitor resolution?

Hello @kartik, Use setLocationRelativeTo(null) This method has a special effect ...READ MORE

answered Apr 21, 2020 in Java by Niroj
• 82,880 points
1,673 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP