Graph API 版本

/{object-id}/comments

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

回應物件可能會有 /comments 關係連線,即回應回覆。其結構與這些關係連線的結構相同,但請留意關係連線的修改參數

讀取

傳回對物件的回應。

對於使用專頁公開內容存取權限功能的應用程式,系統將不再傳回 /PAGEPOST-ID/comments 端點的 id 欄位。如需存取專頁帖子的回應編號,您必須能夠在查詢的專頁上執行 MODERATE 任務。此變更已於 11.0 版及以上版本生效,並將於 2021 年 9 月 7 日在所有版本中實施。

新版專頁體驗

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

  • 相簿
  • 回應
  • 連結
  • 專頁
  • 專頁帖子
  • 相片
  • 帖子
  • 帖子回應

權限

  • 查看母物件所需的權限與查看該物件的回應所需的權限相同。

限制

  • 如有其他用戶存取用戶帖子、相片、相簿、影片、讚好和心情,除非得到他們授權,否則系統不會傳回這些用戶的個人檔案資料和回應。
  • 系統會基於預設的篩選條件在查詢中傳回回應。如要獲取根據您的權限可傳回的所有回應,請將 filter 參數設為 stream,或使用 order 欄位。
  • 新版專頁能以專頁身分在新版專頁或經典專頁上留言。然而,經典專頁不能在新版專頁上的留言。
  • 若您使用用戶存取憑證讀取以下節點的內容,/comments 端點會傳回空白數據:
  • 對於使用專頁公開內容存取權限功能的應用程式,系統將不再傳回 /PAGEPOST-ID/comments 端點id 欄位。如需存取專頁帖子的回應編號,您必須能夠在查詢的專頁上執行 MODERATE 任務
  • 如果物件擁有的回應多得數以萬計,您可能會在分頁時遇到限制。請參閱 Graph API 使用指南,進一步了解有關分頁的資訊。

範例

Graph API 測試工具
GET /v19.0/{object-id}/comments HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/{object-id}/comments',
    '{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}/comments",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{object-id}/comments",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{object-id}/comments"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

參數

GET /v19.0/{object-id}/comments?summary=1&filter=toplevel HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/{object-id}/comments?summary=1&filter=toplevel',
    '{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}/comments",
    {
        "summary": true,
        "filter": "toplevel"
    },
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
Bundle params = new Bundle();
params.putBoolean("summary", true);
params.putString("filter", "toplevel");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{object-id}/comments",
    params,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
NSDictionary *params = @{
  @"summary": @YES,
  @"filter": @"toplevel",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{object-id}/comments"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];
參數 說明

summary

布林值

有關物件回應的中繼資料摘要。請注意,此中繼資料包含的 order 會顯示回應的排序方法。

filter

列舉 { toplevel, stream }

如果用戶可以回覆留言,您就可以根據以下的條件來篩選回應:頂層回應、直接在帖子上作出的回應,或所有回應的時間順序。

  • toplevel:此為預設回應。它會以時間順序傳回所有頂層回應,這和 Facebook 的排序一樣。當您想以出現在 Facebook 的相同回應結構顯示回應時,此篩選條件便會非常有用。
  • stream:以 chronological 順序排列的各層回應。此篩選條件對回應審核工具非常有用,有助工具查看所有回應的時間順序清單。

欄位

當要求的 summarytrue 時,除了以下欄位外,所有欄位將為回應物件陣列。

欄位 說明

order

列舉 { chronological, reverse_chronological }

傳回回應的順序。

  • chronological:由最舊的回應開始排序。
  • reverse_chronological:由最新的回應開始排序。

total_count

int32

此節點上的回應數量。請務必注意,此數值會因您所使用的 filter 而有所變更(若有回應回覆):

  • 如果 filterstream,則 total_count 將為此節點上所有回應(包括回覆)的數量。
  • 如果 filtertoplevel,則 total_count 將為此節點上所有頂層回應的數量。

備註:由於回應私隱設定或回應已刪除,total_count 可能大於或等於系統傳回的實際回應數量。

發佈

向任何物件發佈新回應。

新版專頁體驗

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

  • 回應
  • 專頁帖子
  • 相片
  • 帖子
  • 帖子回應
  • 影片

權限

  • 專頁存取憑證,由可以在專頁上執行 MODERATE 任務的用戶所要求
  • pages_manage_engagement 權限

請注意,各個回應物件can_comment 欄位表示用戶是否可以回覆該回應。

範例

POST /v19.0/{object-id}/comments HTTP/1.1
Host: graph.facebook.com

message=This+is+a+test+comment
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/{object-id}/comments',
    array (
      'message' => 'This is a test comment',
    ),
    '{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}/comments",
    "POST",
    {
        "message": "This is a test comment"
    },
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
Bundle params = new Bundle();
params.putString("message", "This is a test comment");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{object-id}/comments",
    params,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
NSDictionary *params = @{
  @"message": @"This is a test comment",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{object-id}/comments"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

欄位

名稱 說明

attachment_id

字串

要加入為相片回應而上載至 Facebook 的未發佈相片編號(詳見 /{user-id}/photos 中的 no_story 欄位),此為選用項目。必須在發佈時提供下列其中一項:attachment_idattachment_share_urlattachment_urlmessagesource

attachment_share_url

字串

要加入為動畫 GIF 回應的 GIF 網址。必須在發佈時提供下列其中一項:attachment_idattachment_share_urlattachment_urlmessagesource

attachment_url

字串

要加入為相片回應的圖像網址。必須在發佈時提供下列其中一項:attachment_idattachment_share_urlattachment_urlmessagesource

source

multipart/form-data

要用作相片回應的相片(以表格數據形式編碼)。必須在發佈時提供下列其中一項:attachment_idattachment_share_urlattachment_urlmessagesource

message

字串

回應文字。必須在發佈時提供下列其中一項:attachment_idattachment_share_urlattachment_urlmessagesource

使用以下語法以在 message 文字中提及其他 Facebook 專頁:

@[page-id]

必須先通過審查才可使用此功能。

傳回類型

如果成功,您會收到一個 JSON 回應,其中包含最新建立回應的編號。此外,此端點支援先寫後讀,並且可以即時傳回由讀取操作傳回的任何欄位。

{
  "id": "{comment-id}"
}

更新

您無法使用此關係連線作出更新。

刪除

您無法使用此關係連線刪除內容。

請使用 /comment-id 端點來刪除個別回應。