facebookfacebook-graph-apioauth-2.0facebook-oauth

Custom Internal Facebook App Graph API not returning Page's Post Comments


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"
    }
}

Solution

  • I was able to get comments by using the following request:

    https://graph.facebook.com/{post_id}/comments?access_token={accessToken}&summary=true
    

    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.