Graph API Version

Comment /{comment-id}

A comment can be made on various types of content on Facebook. Most Graph API nodes have a /comments edge that lists all the comments on that object. The /{comment-id} node returns a single comment.

Reading

Graph API Explorer
GET /v2.7/{comment-id} HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'GET',
  '/{comment-id}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
/* make the API call */
FB.api(
    "/{comment-id}",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{comment-id}",
    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:@"/{comment-id}"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

Permissions

  • General - To read a comment, you generally need the same permissions as required for viewing the object that the comment was added to.

  • Replies - If this is a comment that is a reply to another comment, the permissions required apply to the object that the parent comment was added to.

  • Hiding Comments - You cannot hide a comment on a page with Graph API if the comment is owned by the page or by a page admin.

Fields

Property NameDescriptionType

id

The comment ID

string

attachment

Link or photo attached to the comment

StoryAttachment

can_comment

Whether the viewer can reply to this comment

bool

can_remove

Whether the viewer can remove this comment

bool

can_hide

Whether the viewer can hide this comment. Only visible to a page admin

boolean

can_like

Whether the viewer can like this comment

boolean

can_reply_privately

Whether the viewer can send a private reply to this comment (Page viewers only)

boolean

comment_count

Number of replies to this comment

int32

created_time

The time this comment was made

datetime

from

The person that made this comment

User

like_count

Number of times this comment was liked

int32

message

The comment text

string

message_tags

An array of Profiles tagged in message.

object[]

id

ID of the profile that was tagged.

string

name

The text used in the tag.

string

type

Indicates which type of profile is tagged.

enum{user, page, group}

offset

Where the first character of the tagged text is in the message, measured in unicode code points.

integer

length

How many unicode code points this tag consists of, after the offset.

integer

object

For comments on a photo or video, this is that object. Otherwise, this is empty.

Object

parent

For comment replies, this the comment that this is a reply to.

Comment

private_reply_conversation

For comments with private replies, gets conversation between the Page and author of the comment (Page viewers only)

Conversation

user_likes

Whether the viewer has liked this comment.

bool

Publishing

You can publish comments by using the /comments edge when it is present on a node.

Deleting

You can delete a comment by using the following endpoint:

DELETE /v2.7/{comment-id} HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'DELETE',
  '/{comment-id}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
/* make the API call */
FB.api(
    "/{comment-id}",
    "DELETE",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{comment-id}",
    null,
    HttpMethod.DELETE,
    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:@"/{comment-id}"
                                      parameters:params
                                      HTTPMethod:@"DELETE"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

Permissions

  • A user access token with publish_actions permission is required to delete a comment posted by that user.
  • A page access token with publish_pages permission is required to delete a comment posted by that Page.
  • Removing comments posted by other people (not the Page itself) on Page posts requires use of a Page access token with manage_pages permission.
  • Reviews are not Page posts, so comments on reviews can not be removed by a Page as they can with Page posts.

Response

If successful:

{
  "success": true
}

Otherwise a relevant error message will be returned.

Updating

You can edit a comment by using the following endpoint:

POST /v2.7/{comment-id} 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',
  '/{comment-id}',
  array (
    'message' => 'This is a test comment',
  )
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
/* make the API call */
FB.api(
    "/{comment-id}",
    "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(),
    "/{comment-id}",
    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:@"/{comment-id}"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

Permissions

  • A user access token with publish_actions permission is required to edit a comment posted by that user.
  • A page access token with publish_pages permission is required to edit a comment posted by that Page.

Fields

NameDescriptionType

message

The updated comment text.

string

is_hidden

Whether this comment is hidden or visible. The original poster can still see the comment, along with the page admin and anyone else tagged in the comment

boolean

Response

If successful:

{
  "success": true
}

Otherwise a relevant error message will be returned.

Edges

Property NameDescriptionType

/likes

People who like this comment.

Edge<Profile>

/comments

Comments that reply to this comment.

Edge<Comment>

/private_replies

Used to send private message reply to this comment (Page viewers only).

Edge<Message>