I am trying to create a Facebook app that can pull down the comments on the posts of a business page I have created. I have successfully created the app and connected my Facebook page through OAuth. However, none of the comments on the page’s posts are coming through. Any help would be appreciated, please see below code.
https://graph.facebook.com/v3.2/{pageId}/?access_token={accessToken}&fields=id,name,posts
Response:
{
"id": "{pageId}",
"name": "Page Name",
"posts": {
"data": [
{
"created_time": "2016-01-15T19:46:28+0000",
"message": "POST 1",
"id": "47829695884833182_111061999222282539"
},
{
"created_time": "2016-01-15T19:45:56+0000",
"message": "POST 2",
"id": "4734458296958848182_111061922795615892"
}
}
}
The same thing happens if I use the following endpoint:
https://graph.facebook.com/v3.2/{pageId}/feed?access_token={accessToken}
Or
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
I found a reference showing I may be able to get comments through this endpoint:
https://graph.facebook.com/v3.2/{pageId}/comments?access_token={accessToken}
However I get the following response:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (comments) on node type (Page)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "EN938TNAHM6"
}
}
2
Answers
I was able to get comments by using the following request:
post_id looks something like this - 57042555475_57045425233226
You have to get comments by posts not pages so first you need to make a call to get all your posts and then make a call for each post to get comments.
With all but the last request you are not asking for comments anywhere. And with the last one you are trying to ask for comments on the page object itself, which are not a thing.
You need to ask for the comments, on either the feed or posts endpoint:
And if you want to get other info about the page as well in the same request, you can use Field Expansion syntax,
(Any other fields of the posts you might want besides the default id, you’d need to list there comma separated –
posts{message,comments,...}
)