图谱 API 版

/{object-id}/comments

本参考文档将介绍多个图谱 API 节点常用的 /comments 连线。每个节点的架构和操作都相同。下列对象均有 /comments 连线:

评论对象可能有 /comments 连线,我们将该连线称为评论回复。这些连线的结构都相同,不过要注意它们的修改参数或会有所差异。

读取

返回有关某个对象的评论。

/PAGEPOST-ID/comments 端点的 id 字段不再对使用公共主页公开内容访问功能的应用返回。如需获取公共主页帖子的评论编号,您必须能够在查询的页面上执行 MODERATE 任务。此项更改适用于 v11.0 及以上版本,并于 2021 年 9 月 7 日对所有版本执行。

新版公共主页体验

新版公共主页体验支持以下对象 /comments 端点:

  • Album
  • Comment
  • Link
  • Page
  • PagePost
  • Photo
  • Post
  • PostComment

权限

  • 查看父对象所需的权限与查看该对象的评论所需权限相同。

限制

  • 访问其他用户的帖子、照片、相册、视频、赞和心情时,除非获得这些用户的授权,否则系统不会返回他们的个人主页信息和评论。
  • 系统基于默认筛选条件返回查询的评论。如要根据您的权限获得可返回的所有评论,请将 filter 参数设为 stream,或使用 order 字段。
  • 新版公共主页能以公共主页身份在新版或经典版公共主页上发表评论,但经典版公共主页不能在新版公共主页上发表评论。
  • 如果您使用用户访问口令读取下列节点,/comments 端点会返回空数据:
  • /PAGEPOST-ID/comments 端点id 字段不再对使用公共主页公开内容访问功能的应用返回。如需获取公共主页帖子的评论编号,您必须能够在查询的页面上执行 MODERATE 任务
  • 对于有数万则评论的对象,您在分页时可能会受到限制。请参阅图谱 API 使用指南,详细了解有关分页的更多内容。

示例

图谱 API 探索工具
GET /v19.0/{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();
/* 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 /v19.0/{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?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
}];
参数 描述

summary

bool

关于对象评论的元数据汇总。值得注意的是,此元数据包含的 order 会显示评论的排序方法。

filter

enum { toplevel, stream }

如果用户可以回复评论,您可以根据顶层评论、直接在某个帖子上发表的评论或所有评论的发表时间顺序来筛选评论。

  • toplevel - 这是默认选项。正如 Facebook 上的排序一样,该选项能够以时间顺序返回所有顶层评论。此筛选参数可用于显示评论,并能采用这些评论在 Facebook 上显示的相同结构。
  • stream - 以 chronological 顺序排列的各层评论。此筛选条件适用于评论审核工具,方便您在其中查看按时间顺序排列的所有评论。

字段

当请求的 summarytrue 时,除以下字段外,还会返回一个评论对象数组。

字段 描述

order

enum { chronological, reverse_chronological }

评论的返回顺序。

  • chronological:评论按时间顺序排序,最早的评论排在最前面。
  • reverse_chronological:评论按时间倒序排序,最新的评论排在最前面。

total_count

int32

此节点上的评论数量。请务必注意,此值会随所使用的 filter 发生更改(评论回复可用时):

  • 如果 filterstream,则 total_count 将为此节点上所有评论(包括回复)的总数。
  • 如果 filtertoplevel,则 total_count 将为此节点上所有顶层评论的总数。

注意:出于评论隐私或删除的原因,total_count 可能大于或等于系统返回的实际评论数量。

发布

发布有关任何对象的新评论。

新版公共主页体验

新版公共主页体验支持以下对象 /comments 端点:

  • Comments
  • PagePosts
  • Photo
  • Post
  • PostComment
  • Video

权限

  • 由可以在公共主页上执行 MODERATE 任务的用户请求的公共主页访问口令
  • pages_manage_engagement 权限

请注意,单个评论对象上的 can_comment 字段表示用户能否回复该评论。

示例

POST /v19.0/{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();
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
}];

字段

名称 描述

attachment_id

字符串

上传到 Facebook 以添加为照片评论的未发布照片编号(参见 /{user-id}/photos 中的 no_story 字段)(可选项)。发布时必须提供以下其中一个字段:attachment_idattachment_share_urlattachment_urlmessagesource

attachment_share_url

字符串

要添加为动图评论的动图网址。发布时必须提供以下其中一个字段:attachment_idattachment_share_urlattachment_urlmessagesource

attachment_url

字符串

要添加为照片评论的图片网址。发布时必须提供以下其中一个字段:attachment_idattachment_share_urlattachment_urlmessagesource

source

multipart/form-data

要用作照片评论的照片(编码为表单数据)。发布时必须提供以下其中一个字段:attachment_idattachment_share_urlattachment_urlmessagesource

message

字符串

评论文本。发布时必须提供以下其中一个字段:attachment_idattachment_share_urlattachment_urlmessagesource

使用以下语法在您的 message 文本中提及其他 Facebook 主页:

@[page-id]

使用此功能需接受审核

返回类型

如果成功,您将收到 JSON 响应,其中包含新创建评论的编号。此外,此端点支持先写入后读取,并且可以即时返回由读取操作返回的任何字段。

{
  "id": "{comment-id}"
}

更新

您无法使用此连线更新评论。

删除

您无法使用此连线删除评论。

您可以使用 /comment-id 端点删除单条评论。