Graph API 版本

物件心情

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

讀取

獲取物件的心情。

查看洞察報告,進一步了解專頁和帖子心情方面的資訊。

新專頁體驗

新專頁體驗支援此端點。

必要條件

推廣應用程式

  • ads_management
  • pages_read_engagement
  • pages_show_list

專頁管理應用程式

  • pages_show_list

要求範例

以下是 GET 要求的範例,由對自己的物件表達心情的用戶所發出。

curl -i -X GET \
 "https://graph.facebook.com/your-post-id/reactions?access_token=your-user-access-token"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/your-post-id/reactions",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/your-post-id/reactions"
           parameters:nil
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/your-post-id/reactions',
  'GET',
  {},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/your-post-id/reactions',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

JSON 回應

{ "data": [ { "id": "your-user-id", "name": "Your Name", "type": "HAHA" } ], "paging": { "cursors": { "before": "QVFIUk5YbXFFbG8yVWVOa2w0ZAGhmSUNKMkZAZAOXZARbzJOMHM0TUFtZAnhJbWdPdkF4OURUTHJrQjFqQ2RQZAVN1UGxSVU5FWURENnE4OUFPeXFreU1jV09pdFJR", "after": "QVFIUkpsWVRkcVl6SlhsdWlrcGdudl8xVEhwVEJ5ZA3FXdG90bTRxam13NmJDUGpQVnB5ZA29lMG9FVmFaeU1BLW1hc2oZD" } } } 

如果用戶或專頁沒有向查詢的物件對象表達心情,則 data 為空。

以下是就某個物件所獲得的總心情數量而提出的 GET 要求範例。

curl -i -X GET \
 "https://graph.facebook.com/your-post-id
   ?fields=reactions.summary(total_count)
   &access_token=your-access-token"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/your-post-id",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "reactions.summary(total_count)");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/your-post-id"
           parameters:@{ @"fields": @"reactions.summary(total_count)",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/your-post-id',
  'GET',
  {"fields":"reactions.summary(total_count)"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/your-post-id',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

如果用戶或專頁已向自己的物件表達心情,JSON 回應如下。

{ "reactions": { "data": [ { "id": "your-user-id", "name": "Your Name", "type": "HAHA" } ], "paging": { "cursors": { "before": "QVFIUk5YbXFFbG8yVWVOa2w0ZAGhmSUNKMkZAZAOXZARbzJOMHM0TUFtZAnhJbWdPdkF4OURUTHJrQjFqQ2RQZAVN1UGxSVU5FWURENnE4OUFPeXFreU1jV09pdFJR", "after": "QVFIUkpsWVRkcVl6SlhsdWlrcGdudl8xVEhwVEJ5ZA3FXdG90bTRxam13NmJDUGpQVnB5ZA29lMG9FVmFaeU1BLW1hc2oZD" } }, "summary": { "total_count": 28 } }, "id": "your-post-id" } 

如果用戶或專頁未有向自己的物件表達心情,JSON 回應如下。

{ "reactions": { "data": [ ], "paging": { "cursors": { "before": "QVFIUk5YbXFFbG8yVWVOa2w0ZAGhmSUNKMkZAZAOXZARbzJOMHM0TUFtZAnhJbWdPdkF4OURUTHJrQjFqQ2RQZAVN1UGxSVU5FWURENnE4OUFPeXFreU1jV09pdFJR", "after": "QVFIUkpsWVRkcVl6SlhsdWlrcGdudl8xVEhwVEJ5ZA3FXdG90bTRxam13NmJDUGpQVnB5ZA29lMG9FVmFaeU1BLW1hc2oZD" } }, "summary": { "total_count": 28 } }, "id": "your-post-id" } 

用戶或專頁只能查詢他們自己的心情。出於私隱考慮,他們無法查詢其他用戶或專頁的心情。

「讚好」心情數目計算包含「讚好」和「加油」心情。

參數

名稱描述

type

列舉 {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

專頁或用戶為物件標記的心情類型。

欄位

此關係連線的讀取操作將傳回 JSON 格式的結果

{ "data": [], "paging": {}, "summary": {} }

data

如果專頁或用戶已向查詢的物件對象表達心情,系統便會顯示執行查詢的專頁或用戶之個人檔案,以及心情類型清單:

欄位描述

type

列舉 {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

專頁或用戶為物件標記的心情類型。

對於帖子上的心情,如果以用戶存取憑證讀取內容,則此關係連線不會傳回除目前用戶以外的個人檔案。

查看單一心情數目計算

curl -i -X GET \
 "https://graph.facebook.com/your-object-id
   ?fields=reactions.type(LOVE).limit(0).summary(total_count)
   &access_token=your-access-token"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/your-object-id",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "reactions.type(LOVE).limit(0).summary(total_count)");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/your-object-id"
           parameters:@{ @"fields": @"reactions.type(LOVE).limit(0).summary(total_count)",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/your-object-id',
  'GET',
  {"fields":"reactions.type(LOVE).limit(0).summary(total_count)"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/your-object-id',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

傳回的 JSON 範例

{ "reactions": { "data": [ ], "summary": { "total_count": 3498 } }, "id": "your-object-id" } 

paging

如要了解分頁詳情,請參閱 Graph API 的分頁文件。將 limit(0) 加入至 reactions 後,系統將從輸出中移除 paging

summary

關於關係連線的彙整資訊,如數目計算。指定用於擷取摘要參數的欄位(如 summary=total_count)。

欄位描述

total_count

未簽名的 int32

心情總數

viewer_reaction

列舉 {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

專頁或用戶為物件標記的心情類型。

錯誤代碼

錯誤描述

100

參數無效

建立

我們並不支援這項操作。

更新

不支援這項操作。

刪除

不支援這項操作。