圖形 API 版本

留言 /{comment-id}

comment 可針對 Facebook 上的各類內容提出。大多數的圖形 API 節點均包含 /comments 關係連線,其中會列出針對該物件提出的所有留言。/{comment-id} 節點會傳回單一 comment

讀取

新版粉絲專頁體驗

此 API 支援全新的粉絲專頁體驗。

權限

  • 一般 – 若要讀取留言,所需權限通常與查看新增留言的物件時所需的權限相同。

  • 回覆 – 若這則留言是另一則留言的回應,所需權限同樣適用於新增上層留言的物件。

  • 粉絲專頁擁有的留言與回覆 – 若是粉絲專頁擁有的留言或回覆,您必須使用粉絲專頁存取權杖才能在回應中註明用戶資訊。

粉絲專頁貼文留言編號格式 {page-id}_{post_id}_{comment-id} 已停用,請改用 {pagepost-id}_{comment-id} 格式。

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