You can use the Live Video API to create live video broadcasts that will go live at a predetermined time, up to seven days from their creation date.
Meta 將在 2024 年 6 月 10 日推出新的必備條件,帳號必須符合這些必備條件才能在 Facebook 上直播。新的必備條件如下:
To create a live video broadcast with a future start date on a User, Page, Group, or Event, send a request to:
POST /<ID>/live_videos?status=SCHEDULED_UNPUBLISHED&event_params=<UNIX_TIMESTAMP_FOR_START_TIME>
Use the event_params
parameter and a UNIX timestamp to indicate the desired start time.
When testing an API call, you can include the access_token
parameter set to your access token. However, when making secure calls from your app, use the access token class.
This will create a LiveVideo
object on the targeted node and return the live video's secure_stream_url
and id
. Use the secure stream URL with your encoder to stream live video data to the LiveVideo
object at, or before, it's scheduled start time. The broadcast will appear on the node's timeline/feed at the planned start time as long as it is receiving stream data.
Scheduled broadcasts can receive streaming data at any point before their start date, for preview purposes.
curl -i -X POST \
"https://graph.facebook.com/v21.0
/<ID>/live_videos?status=SCHEDULED_UNPUBLISHED&event_params=1541539800"
{ "id": "10214937378883406", //LiveVideo object ID "stream_url": "rtmp://rtmp-api.facebook...", "secure_stream_url": "rtmps://rtmp-api.facebook..." //Stream URL }
To get a list of scheduled broadcasts, see Getting Scheduled Broadcasts.
You can use the Live Video API to preview an unpublished live video broadcast; a LiveVideo object created with status
set to SCHEDULED_UNPUBLISHED
or UNPUBLISHED
.
To preview an unpublished live video broadcast, send a request to:
GET /<LIVE_VIDEO_ID?fields={fields}
Use the fields
parameter to get the dash_preview_url
for the LiveVideo
object.
curl -i -X GET \
"https://graph.facebook.com/v21.0
/<LIVE_VIDEO_ID>?fields=dash_preview_url"
{ 'dash_preview_url': 'https://video.xx.fbcdn.net/...', 'id': '<LIVE_VIDEO_ID>' }
This returns the live video's dash_preview_url
and id
. Copy and paste the URL into a Dash Player to preview the broadcast.
Although previewing your broadcast with a third-party test player is a good way to verify the content of your broadcast, we recommend that you broadcast on a test page. You must be a page admin or editor in order to broadcast the page. Additionally you can set the privacy parameter to create streams visible to only you.
To get a list of scheduled broadcasts for a User, Page, or Event, get an appropriate access token with the publish_video
permission and send a request to:
GET /<ID>/live_videos?broadcast_status=["SCHEDULED_UNPUBLISHED"]
Note that the broadcast_status
value must be an array. Refer to the LiveVideo
reference for a complete list of additional values.
curl -i -X GET \
"https://graph.facebook.com/v21.0
/<ID>/live_videos?broadcast_status=["SCHEDULED_UNPUBLISHED"]"
{ "data": [ { "status": "SCHEDULED_UNPUBLISHED", "stream_url": "rtmp://rtmp-api-dev.facebook.com:80/rtmp/...", "secure_stream_url": "rtmps://rtmp-api-dev.facebook.com:443/rtmp/...", "embed_html": "<iframe src=\"https://www.facebook.com/plugins/video.php?...", "id": "10214937378883406 " //LiveVideo object ID } ] }
You can change a scheduled broadcast's start time by sending a request to:
POST /<LIVE_VIDEO_ID>?event_params=<UNIX_TIMESTAMP_FOR_NEW_START_TIME>
The <UNIX_TIMESTAMP_FOR_NEW_START_TIME>
value must be a UNIX time stamp indicating the new start time. Upon success, the API will respond with the LiveVideo
object's ID.
curl -i -X POST \
"https://graph.facebook.com/v21.0
/<LIVE_VIDEO_ID>?event_params=1541540800"
{ "id": "10214937378883406" }
You can start a broadcast immediately by sending a request to:
POST /<LIVE_VIDEO_ID>?status=LIVE_NOW
The broadcast will go live if the stream URL associated with the LiveVideo
object, which represents the broadcast, is receiving stream data. Upon success, the API will respond with the LiveVideo
object's ID.
curl -i -X POST \
"https://graph.facebook.com/v21.0
/<LIVE_VIDEO_ID>?status=LIVE_NOW"
{ "id": "10214937378883406" // <LIVE_VIDEO_ID> }