Questo documento è stato aggiornato.
La traduzione in Italiano non è ancora completa.
Aggiornamento inglese: 5 ott 2020

Trasmissione in diretta

Per trasmettere un video in diretta, devi innanzitutto creare un oggetto LiveVideo. L'oggetto LiveVideo rappresenta la trasmissione in diretta; puoi manipolare le proprietà dell'oggetto per controllare le impostazioni della trasmissione in diretta. Dopo la creazione, l'API restituisce l'ID dell'oggetto LiveVideo e un URL di streaming, che puoi passare al tuo codificatore e usare per trasmettere in streaming i dati all'oggetto LiveVideo.

Trasmettere in diretta su un profilo utente

Per trasmettere in diretta su un profilo utente, ottieni un token d'accesso utente con l'autorizzazione publish_video e invia una richiesta a:

POST /{user-id}/live_videos?status=LIVE_NOW

Consulta il riferimento relativo ai segmenti dei /live_videos per scoprire quali parametri della stringa della query aggiuntivi puoi includere per descrivere il messaggio broadcast, come un titolo o una descrizione.

In caso di azione eseguita correttamente, l'API creerà un oggetto LiveVideo sul profilo utente e restituirà un secure_stream_url e l'id dell'oggetto LiveVideo. Il messaggio broadcast viene visualizzato in un post sul profilo dell'utente non appena invierai i dati all'URL di streaming sicuro. Puoi interrogare l'oggetto LiveVideo per monitorare la qualità del messaggio broadcast e per terminarlo.

Esempio di richiesta

curl -i -X POST \
 "https://graph.facebook.com/{user-id}/live_videos
   ?status=LIVE_NOW
   &title=Today%27s%20Live%20Video
   &description=This%20is%20the%20live%20video%20for%20today.
   &access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{user-id}/live_videos",
  new JSONObject("{\"title\":\"Today's Live Video\",\"description\":\"This is the live video for today.\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{user-id}/live_videos"
           parameters:@{ @"status": @"LIVE_NOW",@"title": @""Today's Live Video"",@"description": @""This is the live video for today."",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{user-id}/live_videos',
  'POST',
  {"status":"LIVE_NOW","title":"\"Today's Live Video\"","description":"\"This is the live video for today.\""},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{user-id}/live_videos',
    array (
      'status' => 'LIVE_NOW',
      'title' => '"Today\'s Live Video"',
      'description' => '"This is the live video for today."'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Esempio di risposta

{
  "id": "1953020644813104",
  "stream_url": "rtmp://rtmp-api.facebook...",
  "secure_stream_url":"rtmps://rtmp-api.facebook..."
}

Trasmettere in diretta su una Pagina

Per trasmettere un video in diretta su una Pagina, ottieni un token d'accesso della Pagina di un amministratore della Pagina con le autorizzazioni pages_read_engagement e pages_manage_posts, quindi invia una richiesta a:

POST /{page-id}/live_videos?status=LIVE_NOW

Consulta il riferimento relativo ai segmenti dei /live_videos per scoprire quali parametri della stringa della query aggiuntivi puoi includere per descrivere il messaggio broadcast, come un titolo o una descrizione.

In caso di azione eseguita correttamente, l'API creerà un oggetto LiveVideo sulla Pagina e restituirà un secure_stream_url e l'id dell'oggetto LiveVideo. Il messaggio broadcast viene visualizzato in un post sulla Pagina non appena invierai i dati all'URL di streaming sicuro. Puoi interrogare l'oggetto LiveVideo per monitorare la qualità del messaggio broadcast e per terminarlo.

Esempio di richiesta

curl -i -X POST \
  "https://graph.facebook.com/{page-id}/live_videos
    ?status=LIVE_NOW
    &title=Today%27s%20Page%20Live%20Video
    &description=This%20is%20the%20live%20video%20for%20the%20Page%20for%20today
    &access_token=EAAC..."
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{page-id}/live_videos",
  new JSONObject("{\"title\":\"Today's Page Live Video\",\"description\":\"This is the live video for the Page for today.\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{page-id}/live_videos"
           parameters:@{ @"status": @"LIVE_NOW",@"title": @""Today's Page Live Video"",@"description": @""This is the live video for the Page for today."",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{page-id}/live_videos',
  'POST',
  {"status":"LIVE_NOW","title":"\"Today's Page Live Video\"","description":"\"This is the live video for the Page for today.\""},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{page-id}/live_videos',
    array (
      'status' => 'LIVE_NOW',
      'title' => '"Today's Page Live Video"',
      'description' => '"This is the live video for the Page for today."'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Esempio di risposta

{
  "id": "1953020644813108",
  "stream_url": "rtmp://rtmp-api.facebook...",
  "secure_stream_url":"rtmps://rtmp-api.facebook..."
}

Trasmettere in diretta su un gruppo

Per poter trasmettere un video in diretta su un gruppo, il gruppo deve installare la tua app. Questa operazione può essere svolta da un amministratore del gruppo su www.facebook.com visualizzando il gruppo, andando su Modifica impostazioni gruppo > App > Aggiungi app e aggiungendo la tua app.

Per trasmettere un video in diretta su un gruppo che ha installato la tua app, ottieni un token d'accesso utente di un amministratore del gruppo con l'autorizzazione publish_video, quindi invia una richiesta a:

POST /{group-id}/live_videos?status=LIVE_NOW

Consulta il riferimento relativo ai segmenti dei /live_videos per scoprire quali parametri della stringa della query aggiuntivi puoi includere per descrivere il messaggio broadcast, come un titolo o una descrizione.

In caso di azione eseguita correttamente, l'API creerà un oggetto LiveVideo sul gruppo e restituirà un secure_stream_url e l'id dell'oggetto LiveVideo. Il messaggio broadcast viene visualizzato in un post sul gruppo non appena invierai i dati all'URL di streaming sicuro. Puoi interrogare l'oggetto LiveVideo per monitorare la qualità del messaggio broadcast e per terminarlo.

Esempio di richiesta

curl -i -X POST \
  "https://graph.facebook.com/{group-id}/live_videos
    ?status=LIVE_NOW
    &title=Today%27s%20Group%20Live%20Video
    &description=This%20is%20the%20live%20video%20for%20the%20group%20for%20today
    &access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{group-id}/live_videos",
  new JSONObject("{\"title\":\"Today's Group Live Video\",\"description\":\"This is the live video for the Group for today.\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{group-id}/live_videos"
           parameters:@{ @"status": @"LIVE_NOW",@"title": @""Today's Group Live Video"",@"description": @""This is the live video for the Group for today."",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{group-id}/live_videos',
  'POST',
  {"status":"LIVE_NOW","title":"\"Today's Groups Live Video\"","description":"\"This is the live video for the Group for today.\""},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{group-id}/live_videos',
    array (
      'status' => 'LIVE_NOW',
      'title' => '"Today's Group Live Video"',
      'description' => '"This is the live video for the Group for today."'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Esempio di risposta

{
  "id": "1953020644813108",
  "stream_url": "rtmp://rtmp-api.facebook...",
  "secure_stream_url":"rtmps://rtmp-api.facebook..."
}

Ottieni dati di streaming del messaggio broadcast

Puoi leggere un oggetto LiveVideo per ottenere gli URL di anteprima dello streaming del messaggio broadcast e i dati sulla qualità dello streaming, come bitrate e frequenza dei fotogrammi. I dati sulla qualità dello streaming si aggiornano ogni 2 secondi, quindi limita le query a non più di una ogni 2 secondi. Ogni 4 secondi di mancata ricezione dei dati viene rilevato e segnalato un timeout dello streaming.

Per leggere un oggetto LiveVideo, ottieni un token d'accesso utente o della Pagina appropriato con l'autorizzazione publish_video, quindi invia una query a:

GET /{live-video-id}?fields={fields}

Usa il parametro {fields} per specificare i campi dell'oggetto LiveVideo che desideri che vengano restituiti. Ad esempio, qui puoi vedere una richiesta per ottenere ingest_streams dell'oggetto LiveVideo, in cui sono inclusi i dati relativi alla qualità dello streaming:

Esempio di richiesta

curl -i -X GET \
  "https://graph.facebook.com/{live-video-id}
    ?fields=ingest_streams
    &access_token={access-token}"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/{live-video-id}",  
  new JSONObject("{\"fields\":\"ingest_streams\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "ingest_streams");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{live-video-id}"     
           parameters:@{ @"fields": @"ingest_streams",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{live-video-id}',     
  'GET',
  {"fields":"ingest_streams"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/{live-video-id}',      
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Esempio di risposta

{
  "ingest_streams": [
    {
      "stream_id": "0",
      "stream_url": "rtmp://rtmp-api.facebook...",
      "secure_stream_url": "rtmps://rtmp-api.facebook...",
      "is_master": true,
      "stream_health": {
        "video_bitrate": 4024116,
        "video_framerate": 60,
        "video_gop_size": 2000,
        "video_height": 720,
        "video_width": 1280,
        "audio_bitrate": 128745.4921875
      },
      "id": "1914910145231512"  // Ingest stream ID
    }
  ],
  "id": "{your-live-video-id}" 
}

Proprietà della risposta

Nome del campoDescrizione
audio_bitrate

Bit al secondo dello streaming audio in entrata.

is_master

true se l'ID del video in diretta interrogato corrisponde al video trasmesso al pubblico.

secure_stream_url

L'URL di inserimento RTMPS sicuro per l'ID del video in diretta interrogato.

stream_url

L'URL di inserimento RTMP per l'ID del video in diretta interrogato.

video_bitrate

Bit al secondo dello streaming video in entrata.

video_framerate

Fotogrammi al secondo dello streaming video in entrata.

video_gop_size

Dimensione GOP (gruppo di immagini) in millisecondi.

video_height

Altezza in pixel del fotogramma video in entrata.

video_width

Larghezza in pixel del fotogramma video in entrata.

Terminare un messaggio broadcast

Per terminare un messaggio broadcast, arresta lo streaming dei dati sul video in diretta dal codificatore all'URL di streaming o invia una richiesta a:

POST /{live-video-id}?end_live_video=true

In questo modo, lo stato dell'oggetto LiveVideo viene impostato su VOD e salvato come video on demand (VOD) per poter essere visualizzato in un secondo momento.

In caso di azione eseguita correttamente, l'API restituirà l'ID dell'oggetto LiveVideo.

Esempio di richiesta

curl -i -X POST \
  "https://graph.facebook.com/{live-video-id}
    ?end_live_video=true
    &access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/live-video-id",
  new JSONObject("{\"end_live_video\":\"true\"}\"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{live-video-id}"
           parameters:@{ @"end_live_video": @"true",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{live-video-id}',
  'POST',
  {"end_live_video":"true"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{live-video-id}',
    array (
      'end_live_video' => 'true'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Esempio di risposta

{
  "id": "10213570560993813"
}

Puoi eseguire un'operazione GET sull'ID del video in diretta per confermare l'impostazione del suo stato su VOD:

GET /{live-video-id}?fields=status

Esempio di risposta

{
  "status": "VOD",  // Broadcast ended, saved as VOD
  "id": "10213570560993813"
}

Eliminare un messaggio broadcast

Per eliminare un messaggio broadcast terminato e salvato come VOD, invia una richiesta a:

DELETE /{live-video-id}

Esempio di richiesta

curl -i -X DELETE \
 "https://graph.facebook.com/{live-video-id}?access_token={access-token}"
Bundle parameters = new Bundle();

GraphRequest request = new GraphRequest(
  accessToken,
  "/{live-video-id}",
  parameters,
  HttpMethod.DELETE,
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"{live-video-id}"
           parameters:nil
           HTTPMethod:@"DELETE"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{live-video-id}',
  'DELETE',
  {},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->delete(
    '/{live-video-id}',
    array (),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Esempio di risposta

{
  success: true
}

Ottenere i dati del codice di errore

Per ottenere i dati del codice di errore associati a un messaggio broadcast, invia una richiesta a:

GET /{live-video-id}?fields=errors

L'API risponderà con error code, type, message e timestamp.

Esempio di risposta

curl -i -X GET \
 "https://graph.facebook.com/{live-video-id}
   ?fields=errors
   &access_token={access-token}"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/1951440638245129",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "errors");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/1951440638245129"
           parameters:@{ @"fields": @"errors",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/1951440638245129',
  'GET',
  {"fields":"errors"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/1951440638245129',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Esempio di risposta

{ "errors": { "data": [ { "error_code": 1969004, "error_type": "stream", "error_message": "Video signal lost", "creation_time": "2018-12-05T23:58:52+0000" }, { "error_code": 1969004, "error_type": "stream", "error_message": "Video signal lost", "creation_time": "2018-12-05T23:58:52+0000" }, { "error_code": 0, "error_type": "info", "error_message": "Live Service received the video signal", "creation_time": "2018-12-05T23:58:02+0000" }, { "error_code": 0, "error_type": "info", "error_message": "Live Service received the video signal", "creation_time": "2018-12-05T23:58:02+0000" } ] }, "id": "{your-live-video-id}" } 
error_subcodeRiepilogo erroriDescrizione
COPYRIGHT__LIVE_COPYRIGHT_VIOLATION

Violazione copyright Live

Il tuo video in diretta è stato interrotto perché potrebbe includere contenuto audio o video appartenente a un'altra Pagina.

VIDEO__CREATE_FAILED

Problema di caricamento

Si è verificato un problema e il tuo video non è stato caricato. Riprova.

LIVE_VIDEO__DELETE_FAILED

Video in diretta non eliminato

Si è verificato un problema e non è stato possibile eliminare il tuo video in diretta. Riprova.

LIVE_VIDEO__EDIT_API_NOT_ALLOWED

La modifica mediante API Video non è consentita durante lo streaming

Non è consentito modificare un video in diretta attraverso l'API Video Edit. Utilizza l'ID del video in diretta.

LIVE_VIDEO__LIVE_STREAM_ERROR

Streaming generico

Si è verificato un problema durante lo streaming

LIVE_VIDEO__NOT_EXIST

Il video in diretta non esiste

Il video in diretta a cui stai provando ad accedere non è più presente nel sistema.

LIVE_VIDEO__PRIVACY_REQUIRED

Impostazione privacy obbligatoria

Devi impostare la privacy prima della diretta streaming.