グラフAPIバージョン

/{app-id}/subscriptions

このエッジにより、アプリ上でWebhooksサブスクリプションを設定することができます。

読み取り

グラフAPIエクスプローラ
GET /v19.0/{app-id}/subscriptions 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(
    '/{app-id}/subscriptions',
    '{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 */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/subscriptions",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/subscriptions"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

アクセス許可

  • アプリのサブスクリプションを返すには、アプリアクセストークンが必要です。

フィールド

名前 説明

object

サブスクリプションの適用対象がこのオブジェクトタイプであることを示します。

enum{user, page, permissions, payments}

callback_url

アップデートがトリガーされたときにPOSTリクエストを受け取るURL。

string

fields

サブスクリプション登録の対象の、このobjectフィールドのセット。

string[]

active

サブスクリプションがアクティブかどうかを示します。

bool

作成

次のエッジを使用して、Webhooksサブスクリプションを新規作成できます。

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

object=page&callback_url=http%3A%2F%2Fexample.com%2Fcallback%2F&fields=about%2C+picture&include_values=true&verify_token=thisisaverifystring
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/{app-id}/subscriptions',
    array (
      'object' => 'page',
      'callback_url' => 'http://example.com/callback/',
      'fields' => 'about, picture',
      'include_values' => 'true',
      'verify_token' => 'thisisaverifystring',
    ),
    '{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 */
Bundle params = new Bundle();
params.putString("object", "page");
params.putString("callback_url", "http://example.com/callback/");
params.putString("fields", "about, picture");
params.putString("include_values", "true");
params.putString("verify_token", "thisisaverifystring");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/subscriptions",
    params,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
NSDictionary *params = @{
  @"object": @"page",
  @"callback_url": @"http://example.com/callback/",
  @"fields": @"about, picture",
  @"include_values": @"true",
  @"verify_token": @"thisisaverifystring",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/subscriptions"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

POSTリクエストでcallback_urlverify_tokenobjectフィールドを指定すると、サブスクリプションを再度有効にできます。

制限

  • Instagram用のWebhooksはサポートされていません。Instagram Webhooksはアプリダッシュボードを使用して設定する必要があります。
  • WhatsApp用のWebhooksはサポートされていません。WhatsApp Webhooksはアプリダッシュボードを使用して設定する必要があります。

アクセス許可

  • アプリのサブスクリプションを新しく追加するには、アプリアクセストークンが必要です。
  • オブジェクトタイプuserへのサブスクリプションは、アプリをインストール済みのユーザーにのみ有効です。
  • オブジェクトタイプpageへのサブスクリプションは、アプリをインストール済みのユーザーにのみ有効です。/{page-id}/subscribed_apps edgeを使用して、ページにアプリをインストールできます。
  • サブスクリプション登録に使用されたアプリがWebhooksのアップデートを受け取るように設定してください。

フィールド

名前 説明

object

サブスクリプションの適用対象がこのオブジェクトタイプであることを示します。

enum{user, page, permissions, payments}

callback_url

アップデートがトリガーされたときにPOSTリクエストを受け取り、この公開操作を試みる際にGETリクエストを受け取るURL。コールバックURLページの構築に関するガイドをご覧ください。

string

fields

サブスクリプション対象にする、このobjectの1つ以上の有効なフィールドのセット

string[]

include_values

変更通知に新しい値を含めるかどうかを示します。

bool

verify_token

リクエストが有効であることをサーバーに確認するために使用できる任意の文字列。

string

応答

コールバックURL が有効で、サブスクリプションに成功した場合、次のようになります。

{
  "success": true
}

成功しなかった場合は、関連するエラーメッセージが返されます。

削除

次の演算を使用して、すべてのサブスクリプションを削除したり、オブジェクトごとにサブスクリプションを削除したりできます。

DELETE /v19.0/{app-id}/subscriptions HTTP/1.1
Host: graph.facebook.com

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

サブスクリプションから特定のフィールドを削除するには、fieldsパラメーターを含めます。

アクセス許可

  • アプリのサブスクリプションを削除するには、アプリアクセストークンが必要です。

フィールド

名前 説明

object

サブスクリプション削除の対象となる、特定のオブジェクトタイプ。この任意のフィールドが含まれていない場合は、このアプリのすべてのサブスクリプションが削除されます。

enum{user, page, permissions, payments}

fields

サブスクリプション対象にする、このobjectの1つ以上の有効なフィールドのセット

string[]

応答

成功した場合は、次のようになります。

{
  "success": true
}

成功しなかった場合は、関連するエラーメッセージが返されます。

更新

このエッジで更新を実行するには、新しい値を指定して公開演算を実行します。これで、既存のフィールドを上書きすることなく、特定のトピックのサブスクリプションを変更することができます。