圖形 API 版本

/{object-id}/likes

此參考資料說明常見於多個圖形 API 節點的 /likes 關係連線。每個節點的結構和操作皆相同。下列物件具有 /likes 關係連線:

讀取

傳回對此物件按讚的用戶名單。讀取粉絲專頁或用戶物件的按讚次數時,這個端點會傳回該粉絲專頁或用戶按讚的粉絲專頁清單。

使用物件的 likes 欄位來取得按讚次數。

建議您使用 /object/reactions 端點來取得按讚次數(如適用)。

新版粉絲專頁體驗

下列物件的 /likes 端點支援新版粉絲專頁體驗:

  • 用戶

必備條件

  • 檢視物件所需的相同必備條件,在檢視該物件的按讚次數時也需要。

限制

  • 只有使用搭配 summary 參數的 total_count 才能彙總貼文的按讚次數。
  • like 心情計數包括「讚」和「加油」心情。
  • total_count 代表按讚次數的估略值,但實際傳回的次數可能因隱私設定而不同。
  • GET /{group-post-id}/likesGET /{post-id}/likes 端點在 8.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
}