Graph API 版本

回應 /{comment-id}

用戶可對 Facebook 的各類內容發表 comment。大多數 Graph API 節點均有 /comments 關係連線,當中列出對特定物件的所有回應。/{comment-id} 節點會傳回單一 comment

讀取

新版專頁體驗

新專頁體驗支援此 API。

權限

  • 一般 - 如要讀取回應,所需權限一般與查看回應所在物件的權限相同。

  • 回應 - 如果此回應是對其他回應的回覆,則所需權限適用於上層回應所在的物件。

  • 由專頁擁有的回應和回覆 — 如果回應或回覆由專頁所擁有,您必須使用專頁存取憑證,才能取得包含用戶資訊的回應。

專頁帖子回應編號格式 {page-id}_{post_id}_{comment-id} 已停用。請改為使用 {pagepost-id}_{comment-id} 格式。

Graph API 測試工具
GET /v19.0/{comment-id} 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(
    '/{comment-id}',
    '{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(
    "/{comment-id}",
    function (response) {
      if (response && !response.error) {
        /* handle the result */
      }
    }
);
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{comment-id}",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{comment-id}"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

欄位

屬性名稱 描述 類型

id

回應編號

string

attachment

附加至回應的連結、影片、貼圖或相片

StoryAttachment

can_comment

瀏覽者能否回覆此回應

bool

can_remove

瀏覽者能否移除此回應

bool

can_hide

瀏覽者能否隱藏此回應;只有專頁管理員才能看到此欄位

boolean

can_like

瀏覽者能否讚好此回應

boolean

can_reply_privately

瀏覽者能否向此回應傳送私人回覆(僅限專頁瀏覽者)

boolean

comment_count

此回應收到的回覆數量

int32

created_time

此回應的發表時間

datetime

from

發表此回應的用戶

User

like_count

此回應獲得的讚好次數

int32

message

回應文字

string

message_tags

message 中標註的個人檔案陣列。

object[]

id

被標註的個人檔案編號。

string

name

標籤所使用的文字。

string

type

表明被標註個人檔案的類型。

enum{user, page, group}

offset

被標註文字的首個字元在 message 中的位置(以 unicode 碼位量度)。

integer

length

此標籤在位移後包含的 unicode 碼位數量。

integer

object

包含相片或影片的帖子回應,包括動態帖子中的回應。如無,此欄位將為空白。

Object

parent

若是回應的回覆,此為回覆所屬的回應。

Comment

private_reply_conversation

若回應含有私人回覆,此欄位可獲取專頁和回應作者之間的對話(僅限專頁瀏覽者)

Conversation

user_likes

瀏覽者有否讚好此回應。

bool

發佈

/comments 關係連線在節點上出現時,您可以使用此關係連線發佈回應。

刪除

您可以使用下列端點來刪除回應:

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

新版專頁體驗

新專頁體驗支援此 API。

必要條件

如要刪除由專頁發佈的回應,您將需要:

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

如要刪除由用戶或其他專頁發佈的回應,您將需要:

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

限制

評論並非專頁帖子,因此專頁無法移除評論上的回應。

回應

如果成功:

{
  "success": true
}

否則系統會傳回相關的錯誤訊息。

更新

您可以使用下列端點來編輯回應:

POST /v19.0/{comment-id} 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(
    '/{comment-id}',
    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(
    "/{comment-id}",
    "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(),
    "/{comment-id}",
    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:@"/{comment-id}"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

新版專頁體驗

新專頁體驗支援此 API。

權限

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

隱藏回應

您可以隱藏帖子上的大部分回應,但以下情況除外:

  • 由專頁發表的回應
  • 由專頁管理員發表的回應
  • 由專頁在用戶帖子上發表的回應;而帖子由該用戶擁有。
  • 任何用戶對其他用戶在專頁上發佈的帖子所發表的回應;而帖子由該用戶擁有。
  • 由活動建立者發表的回應;而帖子由該活動建立者擁有。
  • 由 Facebook 群組發表的回應;而帖子由該群組擁有。
  • 任何用戶對評論所發表的回應

欄位

您必須在更新時提供下列其中一項:attachment_urlattachment_idmessageattachment_share_url

您必須加入一則訊息或一個附件。附件可以是 urlattachment_idattachment_share_url。您可以同時加入 idurl。如果加入 attachment_share_url,則不可加入其他項目。

更新時,您必須加入原始內容所包含的任何值。如果您沒有加入任何一個值,相應的值會在更新後從內容中移除。舉例來說,如果您所更新的回應包含透過 attachment_url 指明的圖像,但您沒有在更新中將其包括在內,此圖像便會移除。

更新支援 /object/comments 發佈部分所列的欄位,當中包括 attachment_urlattachment_idmessagesource。如欲了解這些欄位的詳情,請參閱上述文件。

更新亦支援此處所列的 is_hidden 欄位。

名稱 描述 類型

is_hidden

此回應處於隱藏還是可見狀態。原始發佈者、專頁管理員及回應中被標註的其他用戶仍可以看到此回應

boolean

回應

如果成功,您將會收到包含以下資訊的回應。此外,此端點支援先寫後讀,並且可以即時傳回由讀取操作傳回的任何欄位。

{
  "success": true
}

如果不成功,系統會傳回相關錯誤訊息。

關係連線

屬性名稱 描述 類型
/comments

回覆此回應的回應。

Edge<Comment>
/likes

讚好此回應的用戶。

Edge<Profile>
/reactions

已對此帖子表達心情的用戶。

Edge<Reaction>
/private_replies

用以向此回應傳送私人訊息回覆(僅限專頁瀏覽者)。

Edge<Message>