Graph API-Version

/{app-id}/subscriptions

Mit dieser Edge kannst du Webhooks-Abonnements für eine App konfigurieren.

Lesen

Graph API Explorer
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
}];

Berechtigungen

  • Zur Rückgabe von Abonnements für diese App ist ein App-Zugriffsschlüssel erforderlich.

Felder

Name Beschreibung Typ

object

Gibt den Objekttyp für dieses Abonnement an.

enum{user, page, permissions, payments}

callback_url

Die URL, welche die POST-Anfrage erhält, wenn ein Update ausgelöst wird.

string

fields

Der Satz von Feldern in diesem object-Objekt, die abonniert wurden.

string[]

active

Gibt an, ob das Abonnement aktiv ist.

bool

Erstellen

Mit dieser Edge kannst du neue Webhooks-Abonnements erstellen:

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
}];

Bei einer POST-Anfrage mit diesen callback_url-, verify_token- und object-Feldern wird das Abonnement reaktiviert.

Einschränkungen

  • Webhooks für Instagram werden nicht unterstützt. Instagram-Webhooks müssen über das App-Dashboard konfiguriert werden.
  • Webhooks für WhatsApp werden nicht unterstützt. WhatsApp-Webhooks müssen über das App-Dashboard konfiguriert werden.

Berechtigungen

  • Zum Hinzufügen neuer Abonnements für diese App ist ein App-Zugriffsschlüssel erforderlich.
  • Abonnement für den Objekttyp user sind nur für Nutzer*innen gültig, welche die App installiert haben.
  • Abonnements für den Objekttyp page sind nur für Seiten gültig, welche die App installiert haben. Mit der /{page-id}/subscribed_apps-Edge kannst du die App für eine Seite installieren.
  • Die für das Abonnement verwendete App sollte für den Empfang von Webhooks-Updates eingerichtet sein.

Felder

Name Beschreibung Typ

object

Gibt den Objekttyp für dieses Abonnement an.

enum{user, page, permissions, payments}

callback_url

Die URL, welche die POST-Anfrage erhält, wenn ein Update ausgelöst wird, sowie eine GET-Anfrage, wenn dieser Veröffentlichungsvorgang eingeleitet wird. Mehr dazu erfährst du in unserer Anleitung zum Erstellen einer Rückruf-URL-Seite.

string

fields

Mindestens eines aus der Auswahl gültiger Fehler in diesem object, das abonniert werden soll.

string[]

include_values

Gibt an, ob Änderungsbenachrichtigungen die neuen Werte enthalten sollen.

bool

verify_token

Ein beliebiger String, mit dem du deinem Server gegenüber bestätigen kannst, dass die Anfrage gültig ist.

string

Antwort

Wenn deine Rückruf-URL gültig ist und das Abonnement erfolgreich eingerichtet wurde:

{
  "success": true
}

Ansonsten wird eine entsprechende Fehlermeldung ausgegeben.

Löschen

Mit diesem Vorgang kannst du alle Abonnements oder nur Abonnements für bestimmte Objekte löschen:

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
}];

Du kannst bestimmte Felder aus deinem Abonnement löschen, indem du einen fields-Parameter einschließt.

Berechtigungen

  • Zum Löschen von Abonnements für diese App ist ein App-Zugriffsschlüssel erforderlich.

Felder

Name Beschreibung Typ

object

Ein bestimmter Objekttyp, für den Abonnements entfernt werden sollen. Wenn dieses optionale Feld nicht angegeben wird, werden alle Abonnements für diese App entfernt.

enum{user, page, permissions, payments}

fields

Mindestens eines aus der Auswahl gültiger Fehler in diesem object, das abonniert werden soll.

string[]

Antwort

Bei Erfolg:

{
  "success": true
}

Ansonsten wird eine entsprechende Fehlermeldung ausgegeben.

Aktualisieren

Du kannst Updates für diese Edge vornehmen, indem du einen Veröffentlichungsvorgang mit neuen Werten ausführst. Dadurch wird das Abonnement für das angegebene Thema geändert, ohne dass vorhandene Felder überschrieben werden.