圖形 API 版本

/{object-id}/comments

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

留言物件可能具有 /comments 關係連線,稱為留言回覆。這些關係連線具有相同的結構,但應注意它們的修飾詞

讀取

傳回物件的留言。

系統將不再透過粉絲專頁公開內容存取功能為應用程式傳回/PAGEPOST-ID/comments 端點的 id 欄位。若要存取粉絲專頁貼文的留言編號,您必須能夠在查詢中的粉絲專頁執行 MODERATE 工作。此變更在 11.0 以上版本中生效,將於 2021 年 9 月 7 日在所有版本中實施。

新版粉絲專頁體驗

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

  • 相簿
  • 留言
  • 連結
  • 粉絲專頁
  • 粉絲專頁貼文
  • 相片
  • 貼文
  • 貼文留言

權限

  • 檢視父物件所需的相同權限,在檢視該物件的留言時也需要。

限制

  • 除非獲得用戶的授權,否則在存取用戶貼文、相片、相簿、影片、按讚數和心情回應時,系統不會傳回這些用戶的個人檔案資訊和留言。
  • 查詢中傳回的留言是依據預設的篩選條件。若要取得可根據您的權限傳回的所有留言,請將 filter 參數設為 stream 或使用 order 欄位。
  • 新版粉絲專頁可以在新版粉絲專頁或經典版粉絲專頁上,以粉絲專頁身分留言。但經典版粉絲專頁不能在新版粉絲專頁上留言。
  • 對於下列節點,如果您使用用戶存取權杖讀取,/comments 端點會傳回空資料:
  • 系統將不再透過粉絲專頁公開內容存取功能為應用程式傳回 /PAGEPOST-ID/comments 端點id 欄位。若要存取粉絲專頁貼文的留言編號,您必須能夠在查詢中的粉絲專頁執行 MODERATE 工作
  • 對於具有數萬個留言的物件,您可能會在分頁時遇到限制。深入瞭解使用圖形 API 指南中的分頁。

範例

圖形 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

bool

有關物件留言的中繼資料摘要。重要的是,此中繼資料包含 order,可指出留言的排序方式。

filter

列舉 { toplevel, stream }

在開放用戶回覆留言的情況下,您可以依最上層的留言、直接針對貼文的留言,或是所有留言的時間順序來篩選留言。

  • toplevel - 此為預設值。會依時間前後排列傳回所有最上層的留言,如同 Facebook 上的排列順序。此篩選條件對於將留言以與出現在 Facebook 上相同的結構顯示出來非常有用。
  • stream - 依 chronological 順序排列的各層留言。此篩選條件對於留言審核工具非常有用,有助於查看所有留言的時間前後排列清單。

欄位

summary 在要求中為 true 時,除了下列欄位外的留言物件陣列。

欄位 說明

order

列舉 { chronological, reverse_chronological }

傳回留言的排列順序。

  • chronological:留言依最早留言為先排序。
  • reverse_chronological:留言依最晚留言為先排序。

total_count

int32

此節點的留言計數。必須注意的是,此值根據所使用的 filter 而變更(有可用的留言回覆時):

  • 如果 filterstreamtotal_count 將是節點所有留言(包含回覆)的計數。
  • 如果 filtertopleveltotal_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 端點