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.

Note that 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

Graph API Explorer
GET /v2.7/{object-id}/comments HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'GET',
  '/{object-id}/comments'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* 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
}];

Permissions

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

Fields

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

Property NameDescriptionType

order

Order in which comments were returned.

  • ranked: The most interesting comments are sorted first.
  • chronological: Comments sorted by the oldest comments first.
  • reverse_chronological: Comments sorted by the newest comments first.

enum {ranked, chronological, reverse_chronological}

total_count

The count of comments on this node. It is important to note that this value is changed depending on the filter modifier 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.

total_count can be greater than or equal to the actual number of comments returned due to privacy or deletion

int32

Modifiers

GET /v2.7/{object-id}/comments?summary=1&filter=toplevel HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'GET',
  '/{object-id}/comments',
  array (
    'summary' => true,
    'filter' => 'toplevel',
  )
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* 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
}];
Property NameDescriptionType

summary

Shows a summary of metadata about the comments on the object. Importantly this metadata includes order which indicates how the comments are being sorted.

bool

filter

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

  • toplevel - this is the default, returns all top-level comments in either ranked or chronological order depending on how the comments are 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.

enum{toplevel, stream}

Publishing

You can publish new comments to any object as below:

POST /v2.7/{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 */
$request = new FacebookRequest(
  $session,
  'POST',
  '/{object-id}/comments',
  array (
    'message' => 'This is a test comment',
  )
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* 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
}];

Permissions

  • A user access token with publish_action permission can be used to publish new comments on behalf of that user.
  • A page access token with publish_pages permission can be used to publish new comments on behalf of that Page.
  • The same user or Page must also be able to comment on the object.
  • The can_comment field on individual comment objects indicates whether it is possible to reply to that comment by publishing another.

Fields

NameDescriptionType

message

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

When a Page is publishing the comment, this message parameter can contain mentions of other Facebook Pages using the following syntax:

@[page-id]

For example the following message would mention the Facebook Developers page inline:

Test message @[19292868552] tag

Usage of this feature is subject to review but by using Pages you are an admin of (both to make the API call, and to be used in a mention), and an app you are a developer of, you can test it for yourself before review.

string

attachment_id

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_url, attachment_id, message or source must be provided when publishing.

string

attachment_url

The URL of an image to include as a photo comment. One of attachment_url, attachment_id, message or source must be provided when publishing.

string

source

A photo, encoded as form data, to use as a photo comment. One of attachment_url, attachment_id, message or source must be provided when publishing.

multipart/form-data

Response

If successful:

NameDescriptionType

id

The newly created comment ID

string

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.