简体   繁体   中英

Facebook Graph API: get comments by given user

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="Nitin Thokare",message

/me/feed?fields=comments.fields(from.name("Nitin Thokare"),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.)

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.

eg 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);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM