Graph API Version

/{object-id}/comments

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 has a /comments edge:

For the following nodes, the /comments edge returns empty data if you read it with a User access token:

A User can only query their own comments. Other users' comments are unavailable due to privacy concerns.

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.

Reading

Returns a comment on an object.

Permissions

  • The same permissions required to view the parent object are required to view comments on that object.

Example

Graph API Explorer
GET /v3.2/{object-id}/comments HTTP/1.1
Host: 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();
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
/* 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
}];

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.

Parameters

GET /v3.2/{object-id}/comments?summary=1&filter=toplevel HTTP/1.1
Host: 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",
    {
        "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();
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
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

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

enum{toplevel, stream}

This determines which comments are returned when comment replies are available. It can be either:

  • 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.
  • 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.

Fields

An array of Comment objects in addition to the following fields when summary is true in the request.

Field Description

order

enum {chronological, reverse_chronological}

Order in which comments were returned.

  • chronological: Comments sorted by the oldest comments first.
  • reverse_chronological: Comments sorted by the newest comments first.

total_count

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):

  • if filter is stream then total_count will be a count of all comments (including replies) on the node.
  • if filter is toplevel then total_count will be a count of all top-level comments on the node.

Note: total_count can 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.

Permissions

  • A Page access token for a Page that is able to comment on the object
  • publish_pages permissions granted by a user who is able to comment on the object

Note, the can_comment field on individual comment objects indicates whether it is possible to reply to that comment.

Example

POST /v3.2/{object-id}/comments HTTP/1.1
Host: graph.facebook.com

message=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();
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
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
}];

Parameters

This endpoint doesn't have any parameters.

Fields

Name Type Description

attachment_id

String

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

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

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

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

String

The comment text. One of attachment_id, attachment_share_url, attachment_url, message, or source must be provided when publishing.

Mention other Facebook Pages in your message text using the following syntax:

@[page-id]

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.

{
  "id": "1809938745705498_1809941802371859"
}

Deleting

You can't delete using this edge, however you can delete each comment using the /comment-id node.

Updating

You can't update using this edge.