Videos on a Page
Learn how to upload videos and then fetch uploaded videos on a page.
We'll cover the following
Videos
The video feature on Facebook allows public figures, businesses, and organizations to share video content with their viewers/followers. Page owners can use videos to share announcements, updates, promotions, or other types of content. Videos can be created and managed by page admins and editors with the appropriate permissions. These videos are interactive; users can like, comment, and share them, and they are available on the page's feed once published. Facebook's functionality enhances user engagement by allowing users to watch videos without leaving the platform, autoplaying recommended videos, and other interactive elements, allowing pages to attract more users.
The base URL for this endpoint is:
https://graph.facebook.com/v16.0/{page_id}/videos
Request parameters
The request parameters for the above endpoint are given below.
Parameter | Type | Category | Description |
| String | Mandatory | This is the token that we received in response after making the call to the |
| String | Optional | These are the fields we want in the response from the API call. |
| String | Mandatory | This is the page's ID. Note that this is a path parameter. |
| String | Optional | This is the title of the video. |
| String | Optional | This is the description of the video. |
| String | Mandatory | This is the video file. This can be either a file path or a binary file. |
To publish a new video on the page using the Facebook Graph API, we can make a POST
request to the video
edge of the page
object using the page's ID and a page access token that has the publish_video
permission. The code below uses the endpoint above to publish a new video on the page. Click the “Run” button to see the response.
// Importing libraries hereimport fetch from "node-fetch";import fs from 'fs';import {FormData, Blob} from "formdata-node"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{PAGE_ID}}/videos");const headerParameters = {contentType: "application/json",};// Video Pathconst videoFile = fs.readFileSync('Welcome_to_Educative.mp4');// Define Query Parameters hereconst queryParameters = new URLSearchParams({access_token: '{{PAGE_ACCESS_TOKEN}}',});const body = new FormData();body.append('description', 'This is a sample video');body.append('video_file', new Blob([videoFile]), 'video.mp4');// Setting API call optionsconst options = {method: "POST",headers: headerParameters,body: body};// Function to make API callasync function postVideoOnPage() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callpostVideoOnPage();
In the code widget above:
Line 7: We define the endpoint URL in the
endpointUrl
variable.Line 14: We read the video file using the
readFileSync
function of thefs
library.Lines 17–19: We add the
access_token
in thequeryParameters
variable.Lines 21–23: We create a
FormData
and append thedescription
andvideo_file
to it.Line 36: We use the
fetch
function to make the API call.
Response fields
The response fields for the above endpoint are given below.
Name | Type | Description |
| String | This is the ID of the video. |
| String | This is the description of the video. |
| Object | This is the object containing the ID and name of the user or page that posted the video. |
| String | This is the title of the video. |
| String | This is the video file's URL. |
| String | This is the time the video was created. The time is in ISO 8601 format. |
| String | This is the time the video was updated. The time is in ISO 8601 format. |
Note: To get videos uploaded on a page, remove the
body
and change the method toGET
in theoptions
variable.