This reference describes the /comments edge that is common to multiple Graph API nodes. The structure and operations are the same for each node. The following objects have a /comments edge:
- Album<br> <br>- Comment<br> <br>- Event<br> <br>- Link
- Live Video<br> <br>- Photo<br> <br>- Post
- Thread<br> <br>- User<br> <br>- Video
It is possible for comment objects to have a /comments edge, which is called comment replies. The structure is the same for these, but attention should be paid to the modifiers for these edges.
The id field for the /PAGEPOST-ID/comments endpoint will no longer be returned for apps using the Page Public Content Access feature. To access the comment IDs for a Page post you must be able to perform the MODERATE task on the Page being queried. This change is in effect for v11.0+ and will be implement for all versions on September, 7, 2021.
Other users' profile information and comments will not be returned when accessing user posts, photos, albums, videos, likes, and reactions unless authorized by those users.
Comments returned in a query are based on default filtering. To get all comments that can be returned depending on your permissions, set the filter parameter to stream or use the order field.
For the following nodes, the /comments endpoint returns empty data if you read it with a User access token:
Album
Photo
Post
Video
The id field for the /PAGEPOST-ID/comments endpoint will no longer be returned for apps using the Page Public Content Access feature. To access the comment IDs for a Page post you must be able to perform the MODERATE task on the Page being queried.
For objects that have tens of thousands of comments, you may encounter limits while paging. Learn more about paging in our Using the Graph API Guide.
HTTPPHP SDKJavaScript SDKAndroid SDKiOS SDK Graph API Explorer
GET /v25.0/{object-id}/comments HTTP/1.1Host: graph.facebook.com
/* PHP SDK v5.0.0 *//* make the API call */try { // Returns a `Facebook\FacebookResponse` object $response = $fb->get( '/{object-id}/comments', '{access-token}' );} catch(Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); exit;} catch(Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit;}$graphNode = $response->getGraphNode();/* handle the result */
/* make the API call */FB.api( "/{object-id}/comments", function (response) { if (response && !response.error) { /* handle the result */ } });
/* make the API call */new GraphRequest( AccessToken.getCurrentAccessToken(), "/{object-id}/comments", null, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ } }).executeAsync();
/* make the API call */FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]\ initWithGraphPath:@"/{object-id}/comments"\ parameters:params\ HTTPMethod:@"GET"];[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,\ id result,\ NSError *error) {\ // Handle the result\}];
GET /v25.0/{object-id}/comments?summary=1&filter=toplevel HTTP/1.1Host: graph.facebook.com
/* PHP SDK v5.0.0 *//* make the API call */try { // Returns a `Facebook\FacebookResponse` object $response = $fb->get( '/{object-id}/comments?summary=1&filter=toplevel', '{access-token}' );} catch(Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); exit;} catch(Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit;}$graphNode = $response->getGraphNode();/* handle the result */
/* make the API call */FB.api( "/{object-id}/comments", { "summary": true, "filter": "toplevel" }, function (response) { if (response && !response.error) { /* handle the result */ } });
Bundle params = new Bundle();params.putBoolean("summary", true);params.putString("filter", "toplevel");/* make the API call */new GraphRequest( AccessToken.getCurrentAccessToken(), "/{object-id}/comments", params, HttpMethod.GET, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ } }).executeAsync();
NSDictionary *params = @{ @"summary": @YES, @"filter": @"toplevel",};/* make the API call */FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]\ initWithGraphPath:@"/{object-id}/comments"\ parameters:params\ HTTPMethod:@"GET"];[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,\ id result,\ NSError *error) {\ // Handle the result\}];
Parameter
Description
summary<br> bool
A summary of metadata about the comments on the object. Importantly this metadata includes order which indicates how the comments are being sorted.
filter<br> enum { toplevel, stream }
If a person can reply to a comment, you can filter comments based on top level comments, comments that are made directly on the post, or the chronological order of all comments.<br>- toplevel - This is the default. It returns all top-level comments in chronological order, as ordered on Facebook. This filter is useful for displaying comments in the same structure as they appear on Facebook.<br>- stream - All-level comments in chronological order. This filter is useful for comment moderation tools where it is helpful to see a chronological list of all comments.
Order in which comments were returned.<br>- chronological: Comments sorted by the oldest comments first. <br>- reverse_chronological: Comments sorted by the newest comments first.
total_count<br> int32
The count of comments on this node. It is important to note that this value changes depending on the filter being used (where comment replies are available):<br>- if filter is stream then total_count will be a count of all comments (including replies) on the node.<br>- if filter is toplevel then total_count will be a count of all top-level comments on the node.<br>Note: total_count can be greater than or equal to the actual number of comments returned due to comment privacy or deletion.
POST /v25.0/{object-id}/comments HTTP/1.1Host: graph.facebook.commessage=This+is+a+test+comment
/* PHP SDK v5.0.0 *//* make the API call */try { // Returns a `Facebook\FacebookResponse` object $response = $fb->post( '/{object-id}/comments', array ( 'message' => 'This is a test comment', ), '{access-token}' );} catch(Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); exit;} catch(Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit;}$graphNode = $response->getGraphNode();/* handle the result */
/* make the API call */FB.api( "/{object-id}/comments", "POST", { "message": "This is a test comment" }, function (response) { if (response && !response.error) { /* handle the result */ } });
Bundle params = new Bundle();params.putString("message", "This is a test comment");/* make the API call */new GraphRequest( AccessToken.getCurrentAccessToken(), "/{object-id}/comments", params, HttpMethod.POST, new GraphRequest.Callback() { public void onCompleted(GraphResponse response) { /* handle the result */ } }).executeAsync();
NSDictionary *params = @{ @"message": @"This is a test comment",};/* make the API call */FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]\ initWithGraphPath:@"/{object-id}/comments"\ parameters:params\ HTTPMethod:@"POST"];[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,\ id result,\ NSError *error) {\ // Handle the result\}];
An optional ID of a unpublished photo (see no_story field in /{user-id}/photos) uploaded to Facebook to include as a photo comment. One of attachment_id, attachment_share_url, attachment_url, message, or source must be provided when publishing.
attachment_share_url<br> string
The URL of a GIF to include as a animated GIF comment. One of attachment_id, attachment_share_url, attachment_url, message, or source must be provided when publishing.
attachment_url<br> string
The URL of an image to include as a photo comment. One of attachment_id, attachment_share_url, attachment_url, message, or source must be provided when publishing.
source<br> multipart/form-data
A photo, encoded as form data, to use as a photo comment. One of attachment_id, attachment_share_url, attachment_url, message, or source must be provided when publishing.
message<br> string
The comment text. One of attachment_id, attachment_share_url, attachment_url, message, or source must be provided when publishing.<br>Mention other Facebook Pages in your message text using the following syntax:<br> @[page-id]<br>Usage of this feature is subject to review.
If successful, you will receive a JSON response with the newly created comment ID. In addition, this endpoint supports read-after-write and can immediately return any fields returned by read operations.
/{object-id}/commentsThis reference describes the
/commentsedge that is common to multiple Graph API nodes. The structure and operations are the same for each node. The following objects have a/commentsedge:It is possible for comment objects to have a
/commentsedge, which is called comment replies. The structure is the same for these, but attention should be paid to the modifiers for these edges.Reading
Returns a comment on an object.
The
idfield for the/PAGEPOST-ID/commentsendpoint will no longer be returned for apps using the Page Public Content Access feature. To access the comment IDs for a Page post you must be able to perform the MODERATE task on the Page being queried. This change is in effect for v11.0+ and will be implement for all versions on September, 7, 2021.New Page Experience
The following objects
/commentsendpoint are supported for New Page Experience:Permissions
Limitations
Other users' profile information and comments will not be returned when accessing user posts, photos, albums, videos, likes, and reactions unless authorized by those users.
Comments returned in a query are based on default filtering. To get all comments that can be returned depending on your permissions, set the
filterparameter tostreamor use theorderfield.For the following nodes, the
/commentsendpoint returns empty data if you read it with a User access token:Album
Photo
Post
Video
The
idfield for the/PAGEPOST-ID/commentsendpoint will no longer be returned for apps using the Page Public Content Access feature. To access the comment IDs for a Page post you must be able to perform the MODERATE task on the Page being queried.For objects that have tens of thousands of comments, you may encounter limits while paging. Learn more about paging in our Using the Graph API Guide.
Example
HTTPPHP SDKJavaScript SDKAndroid SDKiOS SDK Graph API Explorer
Parameters
HTTPPHP SDKJavaScript SDKAndroid SDKiOS SDK
summary<br> boolorderwhich indicates how the comments are being sorted.filter<br> enum { toplevel, stream }toplevel- This is the default. It returns all top-level comments in chronological order, as ordered on Facebook. This filter is useful for displaying comments in the same structure as they appear on Facebook.<br>-stream- All-level comments inchronologicalorder. This filter is useful for comment moderation tools where it is helpful to see a chronological list of all comments.Fields
An array of Comment objects in addition to the following fields when
summaryistruein the request.order<br> enum { chronological, reverse_chronological }chronological: Comments sorted by the oldest comments first. <br>-reverse_chronological: Comments sorted by the newest comments first.total_count<br> int32filterbeing used (where comment replies are available):<br>- iffilterisstreamthentotal_countwill be a count of all comments (including replies) on the node.<br>- iffilteristoplevelthentotal_countwill be a count of all top-level comments on the node.<br>Note:total_countcan be greater than or equal to the actual number of comments returned due to comment privacy or deletion.Publishing
Publish new comments to any object.
New Page Experience
The following objects
/commentsendpoint are supported for New Page Experience:Permissions
A Page access token requested by a person who can perform the
MODERATEtask on the PageThe
pages_manage_engagementpermissionNote, the
can_commentfield on individual comment objects indicates whether it is possible to reply to that comment.Example
HTTPPHP SDKJavaScript SDKAndroid SDKiOS SDK
Fields
attachment_id<br> stringno_storyfield in/{user-id}/photos) uploaded to Facebook to include as a photo comment. One ofattachment_id,attachment_share_url,attachment_url,message, orsourcemust be provided when publishing.attachment_share_url<br> stringattachment_id,attachment_share_url,attachment_url,message, orsourcemust be provided when publishing.attachment_url<br> stringattachment_id,attachment_share_url,attachment_url,message, orsourcemust be provided when publishing.source<br> multipart/form-dataattachment_id,attachment_share_url,attachment_url,message, orsourcemust be provided when publishing.message<br> stringattachment_id,attachment_share_url,attachment_url,message, orsourcemust be provided when publishing.<br>Mention other Facebook Pages in yourmessagetext using the following syntax:<br>@[page-id]<br>Usage of this feature is subject to review.Return Type
If successful, you will receive a JSON response with the newly created comment ID. In addition, this endpoint supports read-after-write and can immediately return any fields returned by read operations.
Updating
You can't update using this edge.
Deleting
You can't delete using this edge.
Delete individual comments using the /comment-id endpoint.