Broadcast on a User Feed and Page

Learn how to start a live video on the user feed and page.

Live video
Live video

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

access_token

String

Mandatory

This is the token that we received after app authentication and authorization.

user_id

String

Mandatory

This is the ID of the user. Note that this is a path parameter.

title

String

Optional

This is the title of the live video.

description

String

Optional

This is the description of the live video.

save_vod

Boolean

Optional

This indicates whether a recording of the live video should be saved for later viewing.

published

Boolean

Optional

This indicates whether the live video should be published immediately or be saved as a draft.

status

String

Optional

This is the status of the live video; it can be either LIVE_NOW, SCHEDULED_UNPUBLISHED, or SCHEDULED_PUBLISHED.

schedule_time

DateTime

Optional

This is the date and time when the live video will be broadcast; it is in ISO 8601 format.

is_audio_only

Boolean

Optional

This indicates whether the live video should be audio-only.

ingest_stream_urls

Array

Optional

This is the array of RTMP URLs that we can use to stream to the live video.

encoding_settings

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.

Press + to interact
// Importing libraries here
import fetch from "node-fetch"
// Define endpoint URL here
const endpointUrl = new URL("https://graph.facebook.com/v16.0/{{USER_ID}}/live_videos");
const headerParameters = {
contentType: "application/json",
};
// Setting API call options
const options = {
method: "POST",
headers: headerParameters,
};
// Define Query Parameters here
const 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 call
async function startBroadcast() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
startBroadcast();

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 the title and description, and set the status to LIVE_NOW to specify the state of a live video in the queryParameters 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

id

String

This is the ID of the live video.

status

String

This is the current status of the live video; it can be either LIVE_NOW, SCHEDULED_UNPUBLISHED, or SCHEDULED_PUBLISHED.

title

String

This is the title of the live video.

stream_url

String

This is the URL of the live video's stream.

secure_stream_url

String

This is the secure URL of the live video's stream.

permalink_url

String

This is the URL of the live video on Facebook.

published

Boolean

This indicates whether the live video has been published or not.

created_time

DateTime

This is the time the live video was created. The time is in ISO 8601 format.

updated_time

DateTime

This is the time the live video was updated. The time is in ISO 8601 format.

embed_html

String

This is the HTML code to embed the live video on another website.

start_time

DateTime

This is the time when the live video was started. The time is in ISO 8601 format.

end_time

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.