图谱 API 版

评论 /{comment-id}

Facebook 用户可对各类内容发表 comment。大部分图谱 API 节点拥有 /comments 连线,此连线会列出特定对象的全部评论。/{comment-id} 节点会返回单条 comment

读取

新版公共主页体验

此 API 支持新版公共主页体验。

权限

  • 一般:一般来说,查看评论需要的权限与查看评论对象所需权限相同。

  • 回复:如果一条评论是用于回复另一条评论,则所需权限应用于父级评论的对象。

  • 公共主页自有的评论和回复:对于公共主页拥有的所有评论或回复,如果希望响应中包含用户信息,您必须使用公共主页访问口令。

公共主页帖子评论编号格式 {page-id}_{post_id}_{comment-id} 已停用。改为使用 {pagepost-id}_{comment-id} 格式。

图谱 API 探索工具
GET /v19.0/{comment-id} 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(
    '/{comment-id}',
    '{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(
    "/{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();
/* 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
}];

字段

属性名称 说明 类型

id

评论编号

string

attachment

附加到评论的链接、视频、贴图或照片

StoryAttachment

can_comment

浏览者是否可以回复此评论

bool

can_remove

浏览者是否可以移除此评论

bool

can_hide

浏览者是否可以隐藏此评论。仅公共主页管理员可见

boolean

can_like

浏览者是否可以赞此评论

boolean

can_reply_privately

浏览者是否可以给此评论发送私密回复(仅限公共主页浏览者)

boolean

comment_count

此评论的回复数量

int32

created_time

此评论的发表时间

datetime

from

此评论的作者

User

like_count

此评论的点赞数

int32

message

评论文本

string

message_tags

message 中标记的个人主页数组。

object[]

id

标记的个人主页编号。

string

name

标记中所用的文本。

string

type

表明所标记个人主页的类型。

enum{user, page, group}

offset

标记文本的第一个字符在 message 中所处的位置(用 unicode 代码点衡量)。

integer

length

起始位置之后构成标记的 unicode 代码点数量。

integer

object

包含照片或视频的帖子中的评论,包括动态帖子中的评论。否则此字段为空。

Object

parent

适用于评论回复,此评论为回复对象。

Comment

private_reply_conversation

适用于有私密回复的评论,让公共主页和评论作者之间进行对话(仅限公共主页浏览者)

Conversation

user_likes

浏览者是否点赞此评论。

bool

发布

当节点上存在 /comments 连线时,您可以使用该连线发布评论。

删除

您可以通过使用以下端点删除评论:

DELETE /v19.0/{comment-id} HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->delete(
    '/{comment-id}',
    array (),
    '{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(
    "/{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();
/* 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
}];

新版公共主页体验

此 API 支持新版公共主页体验。

要求

如要删除公共主页发布的评论,您需要:

  • 由可以在公共主页上执行“Moderate(主页维护)”任务的用户请求的公共主页访问口令
  • pages_read_engagement 权限
  • pages_manage_engagement 权限

如要删除用户或另一个公共主页发布的评论,您需要:

  • 由可以在公共主页上执行“Moderate(主页维护)”任务的用户请求的公共主页访问口令
  • pages_manage_engagement 权限
  • pages_read_user_content 权限

限制

点评不属于公共主页帖子,因此公共主页无法移除回复点评的评论。

响应如下

如果成功,则返回:

{
  "success": true
}

否则会返回相关的错误消息。

更新

您可以通过使用以下端点编辑评论:

POST /v19.0/{comment-id} 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(
    '/{comment-id}',
    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(
    "/{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();
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
}];

新版公共主页体验

此 API 支持新版公共主页体验。

权限

  • 由可以在公共主页上执行“Moderate(主页维护)”任务的用户请求的公共主页访问口令
  • pages_read_engagement 权限
  • pages_manage_engagement 权限

隐藏评论

您可以隐藏大部分帖子评论,但以下评论除外:

  • 公共主页发布的评论
  • 公共主页管理员发布的评论
  • 公共主页针对用户帖子发布的评论。此用户为该帖子的拥有者。
  • 用户在另一个用户的帖子中对公共主页发布的评论。此用户为该帖子的拥有者。
  • 活动创作者发布的评论。此活动创作者为该帖子的拥有者。
  • Facebook 小组发布的评论。此小组为该帖子的拥有者。
  • 任何人对点评发布的评论

字段

更新时必须提供下列字段中的其中一个:attachment_urlattachment_idmessageattachment_share_url

您必须提供消息或附件。附件可以是 urlattachment_id 或者 attachment_share_url。您可能需一并提供 idurl。如果提供 attachment_share_url,则您不可以再提供其它字段。

在更新时,您必须提供原始内容中的全部值。如果您未提供其中一个值,则更新完成后该值会遭移除。例如,假设您更新的评论包含通过 attachment_url 指定的图像,如果您在更新时未提供该图像,系统会将其移除。

更新支持 /object/comments 的发布部分所列出的字段。其中包括 attachment_urlattachment_idmessagesource。请查看该文档,获取有关这些字段的详细信息。

更新还支持此处所列的 is_hidden 字段。

名称 说明 类型

is_hidden

评论状态是隐藏还是可见。初始帖子的发布者、公共主页管理员以及评论中所有被标记的人仍然可以看见此评论

boolean

响应如下

如果成功,您会收到包含以下信息的响应。此外,此端点支持先写入后读取,并且可以即时返回由读取操作返回的任何字段。

{
  "success": true
}

如果不成功,系统会返回相关的错误消息。

连线

属性名称 说明 类型
/comments

回复此评论的评论。

Edge<Comment>
/likes

赞此评论的用户。

Edge<Profile>
/reactions

给此帖子留下心情的用户。

Edge<Reaction>
/private_replies

用于给此评论发送私密消息(仅限公共主页浏览者)。

Edge<Message>