图谱 API 版

/{object-id}/likes

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

读取

返回赞此对象的用户列表。在读取对公共主页或用户对象的赞时,此端点会返回该公共主页或用户赞的公共主页列表。

使用对象的 likes 字段来获取赞的数量。

我们建议您使用 /object/reactions 端点来获取赞的数量(如适用)。

新版公共主页体验

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

  • 用户

要求

  • 查看对象所需的条件与查看该对象获赞的所需条件相同。

限制

  • 只有使用 total_countsummary 参数的汇总计数可计为对帖子的赞。
  • like 心情计数包含“赞”和“抱抱”心情。
  • total_count 表示赞的大致数量,但所返回的实际数量可能有所不同,具体取决于隐私设置。
  • GET /{group-post-id}/likesGET /{post-id}/likes 端点已在 v8.0 及更高版本上停用,并将从 2020 年 11 月 2 日起在所有版本中停用。

字段

属性名称 说明 类型

total_count

用户和公共主页对对象的赞数。要返回此字段,您必须在请求中添加 summary=true 参数和值。

int32

使用示例

请求示例
curl -i -X GET "https://graph.facebook.com/{object-id}
  ?fields=likes.summary(true)
  &access_token={access-token}"

响应示例

  {
  "likes": {
    "data": [
      {
        "name": "Bill the Cat",
        "id": "155111347875779",
        "created_time": "2017-06-18T18:21:04+0000"
      },
      {
        "name": "Calvin and Hobbes",
        "id": "257573197608192",
        "created_time": "2017-06-18T18:21:02+0000"
      },
      {
        "name": "Berkeley Breathed's Bloom County",
        "id": "108793262484769",
        "created_time": "2017-06-18T18:20:58+0000"
      }
    ],
    "paging": {
      "cursors": {
        "before": "Nzc0Njg0MTQ3OAZDZD",
        "after": "NTcxODc1ODk2NgZDZD"
      },
      "next": "https://graph.facebook.com/vX.X/me/likes?access_token=user-access-token&pretty=0&summary=true&limit=25&after=NTcxODc1ODk2NgZDZD"
    },
    "summary": {
      "total_count": 136
    }
  },
  "id": "user-id"
}

发布

赞对象。

新版公共主页体验

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

POST /v19.0/{object-id}/likes HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/{object-id}/likes',
    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(
    "/{object-id}/likes",
    "POST",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{object-id}/likes",
    null,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{object-id}/likes"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

权限

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

限制

  • 该公共主页还必须能够赞对象(无论通过 API 还是在 Facebook.com 上)。
  • 此对象不得是该公共主页已赞过的对象。
  • 如果该公共主页已给对象留下心情(哇、心碎),则可以赞,但心情不会改变。
  • 不支持对公共主页点评的赞。

字段

添加赞无需任何字段。

响应

成功后,应用会收到以下响应:

{
  "success": true
}

更新

您无法在此端点上执行此操作。

删除

使用此端点删除对公共主页对象的赞。

DELETE /v19.0/{object-id}/likes 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(
    '/{object-id}/likes',
    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(
    "/{object-id}/likes",
    "DELETE",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{object-id}/likes",
    null,
    HttpMethod.DELETE,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{object-id}/likes"
                                      parameters:params
                                      HTTPMethod:@"DELETE"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

权限

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

限制

  • 用户或公共主页只能删除自己的 likes
  • 必须已赞过该对象。
  • 不支持删除对公共主页点评的赞。

字段

没有用于此端点的字段。

响应

成功后,应用会收到以下响应:

{
  "success": true
}