Facebook Graph API - access the comments and their replies with one query

9.6k Views Asked by At

The following Facebook Graph API v2.6 query:

/{{POST_ID}}/?fields=comments.summary(true)&access_token={{ACCESS_TOKEN}}

will get the comments (with theirs IDs) for the specified Post. Then the query

/{{COMMENT_ID}}/?fields=comments.summary(true)&access_token={{ACCESS_TOKEN}}

will get the replies for the specified Comment.

Is there a way to get both the comments and their replies for given Post with one Graph API query?

4

There are 4 best solutions below

0
On

use filter=stream parameter

https://graph.facebook.com/post_id/comments?access_token=XXXXXXfilter=stream

if you want parent comment id, use fields=parent.fields(id) parameter

https://graph.facebook.com/post_id/comments?access_token=xxxxxx&filter=stream&fields=parent.fields(id)
1
On

I believe this is what you're looking for: https://graph.facebook.com/{the_page_id}_{your_post_id}/comments?fields=message,comments{message,comments}&access_token={your_api_key}

0
On

This will get u the comment replies of comments.

/{{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}}

You can always try out any kind of query at :

https://developers.facebook.com/tools/explorer/

In case you have any doubt on how to form any query, this tool has a search filter on left in which you enter the fields you require and it will automatilcally generate the query for you.

0
On

According to my research you can get post comments and their replies in one query. You can get all comments of post using following API through graph explorer or curl request. Replace {your post id} including braces with your post id.

If you are using graph api explorer then generate page access token to test this API. If you are using curl request that append page access token at the end of URL.

https://graph.facebook.com/v2.10/{your post id}?fields=comments

You can get all replies on all comments of post using following API. It will give you json data containing comment id and all replies to each comment.

https://graph.facebook.com/v2.10/{your post id}?fields=comments{comments}