圖形 API 版本

物件心情

此參考資料說明常見於多個圖形 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"
}

用戶或粉絲專頁只能查詢自己的心情。其他用戶或粉絲專頁的心情因為隱私考量而無法使用。

「like」心情計數同時包括「讚」和「加油」心情。

參數

名稱說明

type

enum {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

粉絲專頁或用戶在物件上標記的心情類型。

欄位

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

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

data

如果查詢的物件有粉絲專頁或用戶傳達心情,為執行查詢的粉絲專頁或用戶的個人檔案,以及心情類型的清單:

欄位說明

type

enum {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

如需分頁的詳細資訊,請參閱圖形 API 的 分頁文件。新增 limit(0)reactions,會將 paging 從輸出中移除。

summary

關於關係連線的彙總資訊,例如計數。在摘要參數中指定要擷取的欄位(如 summary=total_count)。

欄位說明

total_count

未簽署的 int32

心情總數

viewer_reaction

enum {NONE, LIKE, LOVE, WOW, HAHA, SORRY, ANGRY}

粉絲專頁或用戶在物件上標記的心情類型。

錯誤代碼

錯誤說明

100

無效的參數

建立

不支援執行此作業。

更新

不支援執行此作業。

刪除

不支援執行此作業。