Versione API Graph

/{app-id}/subscriptions

Questo segmento ti consente di configurare le iscrizioni ai webhook su un'app.

Lettura

Tool di esplorazione per la API Graph
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
}];

Autorizzazioni

  • Affinché vengano restituite le iscrizioni per un'app, è necessario un token d'accesso all'app.

Campi

Nome Descrizione Tipo

object

Indica il tipo di oggetto a cui si applica l'iscrizione.

enum{user, page, permissions, payments}

callback_url

L'URL che riceverà la richiesta POST quando viene attivato un aggiornamento.

string

fields

L'insieme di campi in questo object a cui è stata effettuata l'iscrizione.

string[]

active

Indica se l'iscrizione è attiva o meno.

bool

Creazione

Puoi creare nuove iscrizioni ai webhook usando questo segmento:

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

Una richiesta POST con i campi callback_url, verify_token e object riattiverà l'iscrizione.

Limitazioni

  • Webhooks per Instagram non è supportato. I webhook per Instagram devono essere configurati utilizzando la Dashboard gestione app.
  • Webhooks per WhatsApp non è supportato. I webhook per WhatsApp devono essere configurati utilizzando la Dashboard gestione app.

Autorizzazioni

  • Per aggiungere nuove iscrizioni per l'app, è richiesto un token d'accesso all'app.
  • Le iscrizioni per il tipo di oggetto user saranno valide solo per gli utenti che hanno installato l'app.
  • Le iscrizioni per il tipo di oggetto page saranno valide solo per le Pagine che hanno installato l'app. Puoi installare l'app per una Pagina usando il segmento /{page-id}/subscribed_apps.
  • L'app usata per l'iscrizione deve essere configurata per ricevere aggiornamenti webhook.

Campi

Nome Descrizione Tipo

object

Indica il tipo di oggetto a cui si applica l'iscrizione.

enum{user, page, permissions, payments}

callback_url

L'URL che riceverà la richiesta POST quando viene attivato un aggiornamento e una richiesta GET quando si tenta questa operazione di pubblicazione. Consulta la nostra guida per la creazione di una pagina URL di callback.

string

fields

Uno o più degliinsiemi di campi validi in questo object a cui effettuare l'iscrizione.

string[]

include_values

Indica se le notifiche di modifica devono includere i nuovi valori.

bool

verify_token

Una stringa arbitraria che può essere usata per confermare al tuo server che la richiesta è valida.

string

Risposta

Se il tuo URL di callback è valido e l'iscrizione è andata a buon fine:

{
  "success": true
}

In caso contrario, viene restituito un messaggio di errore pertinente.

Eliminazione

Puoi eliminare tutte le iscrizioni o solo quelle ai singoli oggetti mediante questa operazione:

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

Puoi eliminare campi specifici dalla tua iscrizione inserendo un parametro fields.

Autorizzazioni

  • Per eliminare iscrizioni per l'app, è richiesto un token d'accesso dell'app.

Campi

Nome Descrizione Tipo

object

Un tipo di oggetto specifico per cui rimuovere le iscrizioni. Se questo campo facoltativo non è incluso, tutte le iscrizioni per l'app saranno rimosse.

enum{user, page, permissions, payments}

fields

Uno o più degliinsiemi di campi validi in questo object a cui effettuare l'iscrizione.

string[]

Risposta

In caso di azione eseguita correttamente:

{
  "success": true
}

In caso contrario viene restituito un messaggio di errore pertinente.

Aggiornamento

Puoi eseguire aggiornamenti su questo segmento eseguendo un'operazione di pubblicazione con nuovi valori. Questa operazione modificherà l'iscrizione per l'argomento senza sovrascrivere i campi esistenti.