Broadcast on a User Feed and Page
Learn how to start a live video on the user feed and page.
We'll cover the following
Broadcasting live videos, also known as live streaming, is a feature on Facebook that allows users to broadcast real-time videos to their followers, friends, or group members. Facebook users can broadcast live videos from personal profiles, pages, or groups. Broadcasting live videos allows users to connect with their audience in real-time, share information and insights, or answer questions. It's an excellent way for businesses and organizations to showcase their products and services or to give behind-the-scenes access to events or activities. It's also an ideal way for educators to deliver lectures and make interactive sessions with their students.
Broadcast on a user feed
To broadcast live on a user's feed, we first need to create a live video by making a POST
request to the /user_id/live_videos
endpoint with the user access token that has the publish_video
permission and relevant parameters. Once the live video is created, we will receive a stream_url
and a stream_key
that we can use to stream the video to Facebook. The base URL for this endpoint is:
https://graph.facebook.com/v16.0/{user_id}/live_videos
Request parameters
The following are the request parameters for the above endpoint.
Parameter | Type | Category | Description |
| String | Mandatory | This is the token that we received after app authentication and authorization. |
| String | Mandatory | This is the ID of the user. Note that this is a path parameter. |
| String | Optional | This is the title of the live video. |
| String | Optional | This is the description of the live video. |
| Boolean | Optional | This indicates whether a recording of the live video should be saved for later viewing. |
| Boolean | Optional | This indicates whether the live video should be published immediately or be saved as a draft. |
| String | Optional | This is the status of the live video; it can be either |
| DateTime | Optional | This is the date and time when the live video will be broadcast; it is in ISO 8601 format. |
| Boolean | Optional | This indicates whether the live video should be audio-only. |
| Array | Optional | This is the array of RTMP URLs that we can use to stream to the live video. |
| String | Optional | These are the encoding settings for the live video. |
The code below uses the endpoint above to create a live video. Click the “Run” button to see the response.
// Importing libraries hereimport fetch from "node-fetch"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/live_videos");const headerParameters = {contentType: "application/json",};// Setting API call optionsconst options = {method: "POST",headers: headerParameters,};// Define Query Parameters hereconst queryParameters = new URLSearchParams({access_token: '{{USER_ACCESS_TOKEN}}',status: 'LIVE_NOW',title: 'Test live video',description: 'This is a test live video',stop_on_delete_stream: true});// Function to make API callasync function startBroadcast() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callstartBroadcast();
In the code widget above:
Line 5: We define the endpoint URL in the
endpointUrl
variable.Lines 18–23: We add the
access_token
, specify thetitle
anddescription
, and set thestatus
toLIVE_NOW
to specify the state of a live video in thequeryParameters
variable.Line 29: We use the
fetch
function to make the API call.
Response fields
The following are the response fields for the above endpoint.
Name | Type | Description |
| String | This is the ID of the live video. |
| String | This is the current status of the live video; it can be either |
| String | This is the title of the live video. |
| String | This is the URL of the live video's stream. |
| String | This is the secure URL of the live video's stream. |
| String | This is the URL of the live video on Facebook. |
| Boolean | This indicates whether the live video has been published or not. |
| DateTime | This is the time the live video was created. The time is in ISO 8601 format. |
| DateTime | This is the time the live video was updated. The time is in ISO 8601 format. |
| String | This is the HTML code to embed the live video on another website. |
| DateTime | This is the time when the live video was started. The time is in ISO 8601 format. |
| DateTime | This is the time when the live video was ended. The time is in ISO 8601 format. |
Note: We can use the same
live_videos
edge with our page ID and group ID to start broadcasting on pages and groups, respectively. To broadcast on a page, we will use a page access token instead of a user access token.