グラフAPIバージョン

/{object-id}/comments

このリファレンスでは、複数のグラフAPIノードに共通する/commentsエッジについて説明します。どのノードも構造と操作は同じです。以下のオブジェクトには/commentsエッジがあります。

コメントオブジェクトには、コメント返信と呼ばれる/commentsエッジが存在する場合があります。この場合も構造は同じですが、エッジの修飾子に注意する必要があります。

読み取り

オブジェクトのコメントが返されます。

/PAGEPOST-ID/commentsエンドポイントのidフィールドは、ページの公開コンテンツへのアクセス機能を使用するアプリでは返されなくなりました。ページ投稿のコメントIDにアクセスするには、クエリ対象のページでMODERATEタスクを実行できることが必須です。この変更はv11.0以上で適用されており、2021年9月7日にすべてのバージョンで実装されます。

新しいページエクスペリエンス

以下のオブジェクトの/commentsエンドポイントは、新しいページエクスペリエンスでサポートされています。

  • アルバム
  • コメント
  • リンク
  • ページ
  • ページ投稿
  • 写真
  • 投稿
  • 投稿コメント

アクセス許可

  • オブジェクトのコメントを表示するには、その親オブジェクトの表示に必要とされるものと同じアクセス許可が必要です。

制限

  • 他のユーザーの投稿、写真、アルバム、動画、「いいね!」、リアクションにアクセスする際に、ユーザーのプロフィール情報やコメントが返されるのは、それらのユーザーから承認されている場合に限られます。
  • クエリで返されるコメントは、デフォルトのフィルター処理に基づいています。アクセス許可に応じて取得可能なすべてのコメントを取得するには、filterパラメーターをstreamに設定するか、orderフィールドを利用してください。
  • 新しいページでは、新しいページにも従来のページにもページとしてコメントすることができます。ただし、従来のページで新しいページにコメントすることはできません。
  • 以下のノードについては、ユーザーアクセストークンを使用して/commentsエンドポイントを読み取ろうとすると、空のデータが返されます。
  • /PAGEPOST-ID/commentsエンドポイントidフィールドは、ページの公開コンテンツへのアクセス機能を使用するアプリでは返されなくなりました。ページ投稿のコメント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

enum { toplevel, stream }

ある人がコメントに返信できる場合、トップレベルのコメント、投稿への直接のコメント、またはすべてのコメントの時系列順にコメントをフィルタリングすることができます。

  • toplevel - これがデフォルトです。最上位レベルのすべてのコメントを、Facebookでの表示順と同じく時系列で返します。このフィルターは、同じ構造の複数のコメントを、Facebookでの表示順と同じ順序で表示する場合に役立ちます。
  • stream - すべてのレベルのコメントをchronologicalの順序で返します。このフィルターは、すべてのコメントの時系列リストを活用できるコメントモデレーションツールに役立ちます。

フィールド

リクエストでsummarytrueに設定された場合、以下のフィールドに加えてコメントオブジェクトの配列が返されます。

フィールド 説明

order

enum { 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

string

写真のコメントとして組み込むためにFacebookにアップロードされた非公開の写真のID(省略可能)。/{user-id}/photosno_storyフィールドをご覧ください。公開する際に、attachment_idattachment_share_urlattachment_urlmessagesourceのいずれかを指定する必要があります。

attachment_share_url

string

アニメーションGIFのコメントとして組み込まれるGIFのURL。公開する際に、attachment_idattachment_share_urlattachment_urlmessagesourceのいずれかを指定する必要があります。

attachment_url

string

写真のコメントとして組み込まれる画像のURL。公開する際に、attachment_idattachment_share_urlattachment_urlmessagesourceのいずれかを指定する必要があります。

source

multipart/form-data

写真コメントとして使用する、フォームデータとしてエンコードされた写真。公開する際に、attachment_idattachment_share_urlattachment_urlmessagesourceのいずれかを指定する必要があります。

message

string

コメントのテキスト。公開する際に、attachment_idattachment_share_urlattachment_urlmessagesourceのいずれかを指定する必要があります。

次の構文を使って、messageテキスト内で他のFacebookページについてメンションします。

@[page-id]

この機能の使用方法はレビューの対象になります

戻り値の型

成功すると、新しく作成されたコメントIDを含むJSON応答を受け取ります。また、このエンドポイントはリードアフターライトをサポートしており、読み取り操作で返されたフィールドをすぐに返すことができます。

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

更新

このエッジを使ってコメントを更新することはできません。

削除

このエッジを使って削除することはできません。

/comment-id endpointを使って個々のコメントを削除します。