Get (Identify) Replies to Comments Using the Graph API
Asked Answered
P

5

7

With the new "Reply" to "Comments" feature on Facebook, I've noticed that replies to comments are treated the same as comments. But I was wondering if there is anyway to distinguish the two?

Palmetto answered 3/4, 2013 at 18:28 Comment(0)
A
5

Yes. You can query each comment object in the Graph API for the value of its parent field. If the comment in question is a reply, then the value of the parent field will be a reference to the parent comment. Otherwise, no value is returned.

Reference here: https://developers.facebook.com/docs/reference/api/Comment/

Aggie answered 4/4, 2013 at 12:50 Comment(2)
Seems like Facebook's API has been modified over the past few days, I can no longer get the replies to comments in the same place where I would get the comments to the post. I now have to send a separate request to the /<comment_id>/comments to get the replies. I liked the old way better, if they could just add the parent id right there. But oh well...Palmetto
This is ridiculous that i have to query each comment to know whether its reply or not, why can't they just include the "parent" value in the /comments api itself ?Shutin
S
12

You first have to enable July Breaking Changes from your app advanced settings

Then use the fields parameter with the comments graph API and include the parent.field(id) column with the and also the filter parameter with the stream value. the final result :

{POST_ID}/comments?filter=stream&fields=parent.fields(id),message,from,likes

this should return both comments and replies with the parent element which has the comment id that the reply belongs to

-- update

and for better array arrangement for replies you can use the following to merge replies with the actual comment array you can include comments.summary(true) in the fields parameter

{POST_ID}/comments?limit=0&filter=toplevel&fields=comments.summary(true),message,from,likes

filter parameter is optional

for more info about the fields : http://developers.facebook.com/docs/reference/api/Comment/

and in case you want to do it in FQL, check this post's comments http://developers.facebook.com/blog/post/2013/04/03/new-apis-for-comment-replies/

Shutin answered 13/5, 2013 at 17:28 Comment(1)
The updated version of this works great, although I had to take out 'limit=0'Wrought
A
5

Yes. You can query each comment object in the Graph API for the value of its parent field. If the comment in question is a reply, then the value of the parent field will be a reference to the parent comment. Otherwise, no value is returned.

Reference here: https://developers.facebook.com/docs/reference/api/Comment/

Aggie answered 4/4, 2013 at 12:50 Comment(2)
Seems like Facebook's API has been modified over the past few days, I can no longer get the replies to comments in the same place where I would get the comments to the post. I now have to send a separate request to the /<comment_id>/comments to get the replies. I liked the old way better, if they could just add the parent id right there. But oh well...Palmetto
This is ridiculous that i have to query each comment to know whether its reply or not, why can't they just include the "parent" value in the /comments api itself ?Shutin
D
3

You can get comment replies in this way.

/{{POST_ID}}/?fields=comments{comments}&access_token={{ACCESS_TOKEN}}

You can get any sub info(from,id) of comment replies by just nesting fields inside comments like this:

/{{POST_ID}}/?fields=comments{comments,from,id}&access_token={{ACCESS_TOKEN}}

Similar post over here : https://mcmap.net/q/1476391/-facebook-graph-api-access-the-comments-and-their-replies-with-one-query

Dogs answered 10/6, 2016 at 8:33 Comment(0)
S
0

If you're listening for comments on the 'feed' webhook, you should check if:

entry[0][changes][0][value][post_id] === entry[0][changes][0][value][parent_id]

This will be true for top-level (new) comments, and false for replies to comments.

Stome answered 11/9, 2017 at 6:23 Comment(0)
K
-1

To piggy back off @sujit's answer I took his answer and in one call from the feed you can get the entire feed, comments and replies to comments as well as associated images to those comments and replies in one shot.

Here is the code

https://graph.facebook.com/$get_facebook/feed?access_token=$facebook_accesstoken&client_id=$facebook_appid&client_secret=$facebook_appsecret&metadata=1&fields=id,status_type,created_time,from,message,comments{comments{attachment,from,id,message},from,id,message,attachment},picture,link,icon
Killjoy answered 21/6, 2017 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.