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 in Java by kartik
• 20,470 points

edited May 7 by kartik 859 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 by Niroj
• 43,540 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
• 55,420 points
192 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,890 points
717 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,630 points
912 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,150 points
132 views
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,190 views
0 votes
0 answers
0 votes
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 in Java by Niroj
• 43,540 points
48 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 in Java by Niroj
• 43,540 points
27 views