讀取
獲取物件的心情。
查看洞察報告,進一步了解專頁和帖子心情方面的資訊。
新專頁體驗
新專頁體驗支援此端點。
必要條件
推廣應用程式
ads_management
pages_read_engagement
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} | 專頁或用戶為物件標記的心情類型。 |
錯誤代碼