Include and exclude specific audiences from viewing your Live Video.
manage_pages
, publish_pages
, and publish_video
permissions.publish_video
permissions.Send a POST /id
request where id
is the live-video-id and set the targeting
field and it's parameters.
curl -i -X POST \
"https://graph.facebook.com/{your-live-video-id}
?targeting={age_min:17, geo_locations:{countries:["US","CA","MX"]}}
&access_token={your-access-token}"
{ "targeting": { "age_max": 65, "age_min": 17, "geo_locations": { "countries": [ "US", "CA", "MX" ] } }, "id": "{your-live-video-id}" }
manage_pages
, publish_pages
, and publish_video
permissions.publish_video
permissions.Send a GET /id
request where id
is the live-video-id with the targeting
field.
curl -i -X GET \
"https://graph.facebook.com/{your-live-video-id}
?fields=targeting&access_token={your-access-token}"
{ "targeting": { "age_max": 65, "age_min": 17, "geo_locations": { "countries": [ "US" "CA", "MX" ] } }, "id": "{your-live-video-id}" }
Continuous live video supports an unlimited live stream on Facebook. Some great use cases for continuous live include live feeds of aquariums, museums, and zoos.
Before streaming, please note:
manage_pages
, publish_pages
, and publish_video
permissions.publish_video
permissions.Send a POST /id/live_videos
request where id
is your group-id or page-id with the stream_type
parameter set to AMBIENT
.
curl -i -X POST \
"https://graph.facebook.com/{your-page-id}/live_videos
?stream_type=AMBIENT
&access_token={your-page-access-token}"
{ "id": "{live-video-id}", "stream_url": "rtmp://rtmp-api-dev.facebook.com:80/rtmp/{live-video-id}?s_l=1&s_sw=0&s_vt=api_dev&a=AbxrzdR83iK_3b641ac", "secure_stream_url": "rtmps://rtmp-api-dev.facebook.com:443/rtmp/{live-video-id}?s_l=1&s_sw=0&s_vt=api_dev&a=AbxrzdR83iK_3b64FDg" }
manage_pages
, publish_pages
, and publish_video
permissions.publish_video
permissions.Send a POST id
request, where id
is the live-video-id, with the end_live_video
parameter set to true
.
curl -i -X POST \
"https://graph.facebook.com/{your-live-video-id}
?end_live_video=true
&access_token={your-page-access-token}"
{ "id": "{your-video-id}" // Now a VOD video-id }
We've created a plugin to make the process of Live API integration as easy as possible enabling you to authenticate with Facebook, preview your live stream, and describe your live stream through a pop-up window before going live. This dialog is best suited for those streaming from the client side. Backend integrations should continue to use the API directly.
To initialize a pop-up window with controls that determine where to direct your POST
response insert the following code.
<button id="liveButton">Create Live Stream To Facebook</button> <script> document.getElementById('liveButton').onclick = function() { FB.ui({ display: 'popup', method: 'live_broadcast', phase: 'create', }, function(response) { if (!response.id) { alert('dialog canceled'); return; } alert('{your-stream-url}:' + response.secure_stream_url); FB.ui({ display: 'popup', method: 'live_broadcast', phase: 'publish', broadcast_data: response, }, function(response) { alert("video status: \n" + response.status); }); }); }; </script>
Parameters | Value | Description |
---|---|---|
|
| How the dialog is open in your web page. |
|
| Dialog in create phase allows you to get stream url to upload video; Dialog in publish phase will provide preview and go live button. |
| The response | This parameter is |
In the Create phase pop-up window, choose the live stream destination which can be on any pages or groups you manage. The POST
response will include the stream_url
and secure_stream_url
fields. Either one can be broken out into a server URL and stream key.
The server URL is the first half of the stream_url: rtmp://rtmp-api.facebook.com:80/rtmp/
The stream key is the latter half of the stream_url: 10153307708286557?ds=1&a=AdrRKk4mOaqPbQdxDuk
Response Field | Phase | Description |
---|---|---|
|
| The ID of broadcast video. |
|
| A rtmp url that contains stream server and stream key used to upload the live stream. |
|
| A rtmps url, the stream url with secure protocol. |
|
| String value indicating the status of broadcast. |
In our code snippet, we have an alert
call with the stream_url
. Your client should start streaming using stream_url
. Soon after the stream starts, you will notice a preview of the broadcast appear in the publish phase pop-up window. The dialog enables users to choose privacy settings without adjusting the request's privacy parameter and to set the Live video description, title, and topic tags.
Note: If the publish pop-up window is Offline, ensure that your firewall is not blocking RTMP and that any Adblocker software on your browser is turned off.
When you click Go Live, the dialog will close and within a few seconds, the live stream play on the page or group, according to the chosen destination.
With the latest updates, released on Sept. 11, 2017, metadata is injected into the first frame of a live video with frame-accurate start times. Encoders can now implement a countdown to alert publishers to the exact start of the video. You can also start and stop the video from the Facebook interface.