How to get from field of a facebook comment using Graph API

310 views Asked by At

I am using the comment-id to get the from field and using the page access token:

[comment-id]?fields=from&access_token=[PAGE_ACCESS_TOKEN]

But I am not getting the desired output, I am getting back the comment-id only

{
  "id": "[comment-id]"
}

I am not getting what mistake I am making here.

Any help is appreciated. TIA

1

There are 1 answers

0
Arpit Jain On

Use the {pagepost-id}_{comment-id} format instead.

Example Request:-

curl -i -X GET \
 "https://graph.facebook.com/v17.0/222277054012345_979370980112345?access_token=<YOUR_PAGE_ACCESS_TOKEN>"

Response:-

{
  "created_time": "2023-06-25T06:25:41+0000",
  "from": {
    "name": "John doe",
    "id": "111282025112345"
  },
  "message": "This is to explore FB comment API.",
  "id": "222277054012345_979370980112345"
}

Additionally, To get all the comments made on a Facebook page post you can use the following API call:-

Request:-

curl -i -X GET \
 "https://graph.facebook.com/v17.0/111282025112345_222277054012345/comments?access_token=<YOUR_PAGE_ACCESS_TOKEN>"

Here in the URL, 111282025112345 is page_id and 222277054012345 is post_id.

Response:-

{
  "data": [
    {
      "created_time": "2023-06-25T06:25:41+0000",
      "from": {
        "name": "John doe",//Comment Author's name
        "id": "111282025112345"//Comment Author's id
      },
      "message": "This is to explore FB comment API.",
      "id": "222277054012345_979370980112345" //`{pagepost-id}_{comment-id}`
    }
  ],
  "paging": {
    "cursors": {
      "before": "MgZDZD",
      "after": "MQZDZD"
    }
  }
}

Hope this helps.