Graph API 版本

/{object-id}/likes

本參考文件將講述多個 Graph API 節點常用的 /likes 關係連線。所有節點的架構和操作都為相同。下列物件均有 /likes 關係連線:

讀取

傳回讚好此物件的用戶清單。在讀取對專頁或用戶物件的讚好時,此端點會傳回該專頁或用戶讚好的專頁清單。

使用物件的 likes 欄位獲取讚好次數。

我們建議您使用 /object/reactions 端點獲取讚好次數(如適用)。

新版專頁體驗

新版專頁體驗支援以下物件 /likes 端點:

  • 用戶

必要條件

  • 查看物件所需的權限與查看該物件的讚好所需的權限相同。

限制

  • 僅採用 total_count 的彙總數目計算和 summary 參數適用於帖子讚好。
  • 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
}