How to post Facebook Reels using the Social Media API
[ad_1]
If you’ve been a bit of a social outcast, short videos are all the rage right now – videos that are typically 3 to 60 seconds long and are displayed vertically on your phone. Ever since TikTok started the short-form video trend, every social media competitor has created their own version. Instagram with Instagram Reels, YouTube and YouTube Shorts, and more recently Facebook Reels. Not only that, networks have been busy updating their API integrations for short videos: Instagram API, TikTok API, and YouTube API. Everything except Facebook, ie Meta…until now with the new Facebook Reels API.
What are Facebook Reels
Launched in September 2021, Facebook Reels is the answer to TikTok’s short videos. As Facebook says:
Reels on Facebook can contain music, sound, effects and more. You can find them in News Feeds or Groups, and when you watch a reel on Facebook, you can easily follow the creator directly from the video, like and comment on it, or share it with friends.
Reels have different video requirements:
- Duration: Up to 60 seconds and more than 3 seconds.
- Format: MP4 (.mp4) video.
- Minimum 1080P, and 4K if available (note: video will be uploaded to 720p after upload)
- Aspect ratio loading: 9:16.
Creating Facebook Reels is as easy as recording a video on your mobile phone. In the Reels example below the format is 9:16, i.e. recorded on a mobile phone.
Facebook has also focused on helping creators make money with their Facebook Reels Play Bonus program. How much money can you make? Basically if you have more than 100K views within 30 days, you will start earning up to $4,000 per month. Additionally, there are “challenges” to get more money.
Facebook Social Media APIs
The Facebook Graph API recently introduced the ability to directly share Reels videos through their Reels Publishing API. Previously you could only share the Facebook platform through the iOS or Android app, but now you can post directly to their Reels API repository.
There are two steps you must complete before using the FB Reels API:
- Facebook APIs use standard OAuth endpoints with sending permission tokens. OAuth allows users to authorize and grant permissions to your application. These tokens are short-lived, but can be replaced with long-lived page tokens. While we won’t go into depth, it’s important to note that you can only post Reels to Facebook pages. Posting Reels to personal accounts or Group pages is prohibited by Facebook.
- Facebook requires you to request authorization and go through an API review process with permission access (
pages_show_list
,pages_read_engagement
againpages_manage_posts
permits), which can take several days to several weeks. You’ll need to first create your app/integration, record a usage video, and write permissions using Facebook’s developer portal. Expect to be rejected the first few times.
Facebook Reels API
Ok, now for the fun stuff…let’s try using the FB Reels API to post a video.
There are three steps to integrating the Facebook API to post a short form Reel video. Here is an example of a video we will post.
Reels Posting API Step 1
Start the video upload by calling video_reels
endpoint. The answer is the video’s identity and upload URL.
GET
The required criteria for the query are:
upload_phase=start
access_token={access_token}
I {page-id}
as well as {access_token}
the Facebook page id and the access token provided during OAuth, respectively.
Here’s an example in JavaScript:
const uploadStartUri = `
const initiateUploadResponse = await fetch(uploadStartUri, { method: "POST" })
.then((res) => res.json())
.catch((err) =>
console.log("Error initiating upload for FB Reels:", uploadStartUri, err)
);
const { video_id, upload_url } = initiateUploadResponse;
Answer to initiateUploadResponse
to be used in step 2:
{
"video_id": "{video-id}",
"upload_url": "
}
Reels Posting Step 2
The next step is to upload the actual video. There are two ways: upload a local file as an app/octet stream or provide an externally accessible video URL. We will focus on the URL method for external access.
Using the response from step 1, make a request to the upload URL with the video id, your URL, and the access token.
POST
Note the separate subdomain of rupload
instead of normal graph
sub domain.
The required POST parameters are:
- Head
Authorization: "Oauth {access_token}"
- Head
file_url: {url}
When i access_token
is the same Access symbol from above and url
the URL of your externally accessible video.
Here’s an example in JavaScript:
const options = {
method: "POST",
maxBodyLength: Infinity,
headers: {
Authorization: `OAuth ${access_token}`,
file_url: url,
},
};
const uploadResponse = await fetch(upload_url, options)
.then((res) => res.json())
.catch((err) =>
console.error(
"Error uploading binary for Facebook Reels",
upload_url,
options,
err
)
);
The response is not visible if everything is successful:
{"success": true}
Reels Posting Step 3
We’re almost done. Now the video needs to be published, which requires one last call.
POST
The required POST parameters are:
access_token={access_token}
video_id={video_id}
upload_phase="finish"
video_state="PUBLISHED"
description="The video description text"
title="Video title"
(optional)
Let’s see and do an example in JavaScript:
const title = "Super Title";
const description = "Best Reel ever";
const basePublishReelsURI = `
auth.id
}/video_reels?upload_phase=finish&video_id=${video_id}title=${title}&description=${description}&video_state=PUBLISHED&access_token=${access_token}`;
const publishReelsResponse = await fetch(basePublishReelsURI, {
method: "POST",
})
.then((res) => res.json())
.catch((err) =>
console.error("Error publishing for Facebook Reels:", basePublishReelsURI, err)
);
And, if all is successful the response is invisible:
{"success": true}
Your Reel is now published!
Bonus API call
If you want to check the status of Reel – errored, still processing, or fully published – you can call the repository:
GET
An alternative to the Facebook API
Another option to integrate directly with the Facebook API is the Ayrshare social media API, which includes Facebook Reels API integration. You no longer need to be authorized or worry about Facebook’s dynamic API details.
For example, to post a new Facebook Reels video use the following Javascript code with the /post endpoint. Be sure to replace API_KEY with your key in the dashboard:
const data = {
"post": "The description of the video",
"platforms": ["facebook"],
"mediaUrls": "
"faceBookOptions": {
"reels": true,
"title": "Super title for the Reel" // optional
}
};
const requestOptions = {
method: 'POST',
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify(data)
};
fetch(" requestOptions)
.then(res => res.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));
or if you prefer in Python:
import requests payload = {'post': 'Today is a good day!', 'platforms': ['facebook']'mediaUrls': ['
'faceBookOptions': {
'reels': true,
'title': 'Super title for the Reel'
}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('
json=payload,
headers=headers)
print(r.json())
It is that easy using Ayrshare.
Facebook Analytics API
In addition to posting short form video Reels to Facebook, you also might want Facebook analytics about the user’s account or individual post, such as how many views, shares, or likes. These insights into user behavior, engagement, and reach can help build your social media strategy.
For example, to get the user level analytics across all their Facebook videos call the Ayrshare /analytics API endpoint. Here is the code in Javascript:
const data = { platforms: ["facebook"] }; const requestOptions = { method: 'SUBMIT', headers: { "Authorization": `Bearer ${API_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify(data) }; fetch(" requestOptions) .then(res => res.json()) .then(result => console.log(result)) .catch(error => console.log('error', error));
Or call analytics in Python:
import requests
payload = {'platforms': ['facebook']}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('
json=payload,
headers=headers)
print(r.json())
Detailed Facebook statistics are returned, such as followers, likes, demographics, and more.
{
"facebook": {
"analytics": {
"about": "What to watch next? Create private groups with your friends to get recommendations on the next movie or show to watch.",
"birthday": "11/20/1985", // Applicable to Pages representing people
"emails": ["[email protected]"],
"engagement": {
"count": 587,
"socialSentence": "587 people like this."
},
"fanCount": 587,
"followersCount": 587,
"id": "102619320979033",
"link": "
"location": {
"street": "142 W 57th St",
"zip": "10019"
}
"name": "theGoodone",
"pageConsumptions": 11, // The number of times people clicked on any of your content.
"pageConsumptionsByConsumptionType": {
"link clicks": 3,
"other clicks": 4,
"video play": 4
},
"pageEngagedUsers": 1234, // The number of people who engaged with your Page. Engagement includes any click.
"pageFansByLikeSource": {}, // Daily: This is a breakdown of the number of Page likes from the most common places where people can like your Page. (Total Count)
"pageFansByLikeSourceUnique": {}, // Daily: The number of people who liked your Page, broken down by the most common places where people can like your Page. (Unique Users)
"pageFansCity": { // Lifetime: Aggregated Facebook location data, sorted by city (top 50), about the people who like your Page. (Unique Users)
"Seattle, United States of America": 1,
"Ras al-Khaimah, United Arab Emirates": 1,
"Mexico City, Mexica": 1,
...
},
"pageFansCountry": { // Lifetime: Aggregated Facebook location data, sorted by country (top 50), about the people who like your Page. (Unique Users)
"BD": 1,
"EG": 1,
...
},
"pageFansGenderAge": { // Lifetime: Aggregated demographic data about the people who like your Page based on the age and gender information they provide in their user profiles. (Unique Users)
"M.25-34": 92,
"F.13-17": 1,
"M.55-64": 1,
...
},
"pageFansLocale": { // Lifetime: Aggregated language data about the people who like your Page based on the default language setting selected when accessing Facebook. (Unique Users)
"bn_IN": 3,
"es_LA": 6,
"pa_IN": 1,
...
},
"pageFanRemoves": 1, // Unlikes of your Page.
"pageImpressions": 160, // The number of times any content from your Page or about your Page entered a person's screen. This includes posts, stories, ads, as well other content or information on your Page.
"pageImpressionsPaid": 23, // The number of times any post or story content from your Page or about your Page entered a person's screen through paid distribution such as an ad.
"pagePostEngagements": 20, // The number of times people have engaged with your posts through reactions, comments, shares and more.
"pagePostsImpressions": 124, // The number of times your Page's posts entered a person's screen. Posts include statuses, photos, links, videos and more.
"pagePostsImpressionsPaid": 34, // The number of times your Page's posts entered a person's screen through paid distribution such as an ad.
"pageVideoViewTime": 10232, // The total time, in milliseconds, people viewed your Page's video.
"pageVideoViews": 31, // The number of times your Page's videos played for at least 3 seconds, or for nearly their total length if they're shorter than 3 seconds. During a single instance of a video playing, we'll exclude any time spent replaying the video.
"pageVideoViewsPaid": 6, // The number of times your Page's promoted videos played for at least 3 seconds, or for nearly their total length if they're shorter than 3 seconds. For each impression of a video, we'll count video views separately and exclude any time spent replaying the video.
"reactions": { // Total over past 180 days
"like": 1, // Like reactions - The "like" reaction counts include both "like" and "care" reactions.
"love": 1, // Love reactions
"anger": 1, // Anger reactions
"haha": 1, // Haha reactions
"wow": 1, // Wow reactions
"sorry": 1, // Sorry reactions
"total": 6 // Total number of reactions
},
"username": "theGoodone",
"verified": true, // verified Facebook Page
"website": "
}
}
}
If you want to get analytics for each Facebook post, call the /analytics post endpoint. Post-level statistical data returned includes shares, likes, impressions, clicks, and more:
{
"facebook": {
"id": "1397547544885713_2159201585286968", // ID of the post at Facebook
"postUrl": "
"analytics": {
"impressionsUnique": 3, // People who had your Page's post enter their screen. Posts include statuses, photos, links, videos and more.
"engagedUsers": 63, // People who clicked anywhere in your posts.
"clicksUnique": 2, // Times people clicked on anywhere in your posts.
"commentCount": 1, // Count of comment for the post
"impressionsUnique": 1, // Count of unique impressions
"likeCount": 0, // Count of likes for the post
"negativeFeedback": 1, // Times people took a negative action in your post (e.g. hid it).
"negativeFeedbackUnique": 1, // Unique times people took a negative action in your post (e.g. hid it).
"reactions": {
"like": 1, // Like reactions - The "like" reaction counts include both "like" and "care" reactions.
"love": 1, // Love reactions
"anger": 1, // Anger reactions
"haha": 1, // Haha reactions
"wow": 1, // Wow reactions
"sorry": 1, // Sorry reactions
"total": 6 // Total number of reactions
},
"videoViewTime": 0, // Time, in milliseconds, your videos played, including videos played for less than 3 seconds and replays
"videoViews": 0, // Times your videos played for at least 3 seconds, or for nearly their total length if they're shorter than 3 seconds. During a single instance of a video playing, we'll exclude any time spent replaying the video. This includes live views.
"videoViewsUnique": 0, // Unique times your videos played for at least 3 seconds, or for nearly their total length if they're shorter than 3 seconds. During a single instance of a video playing, we'll exclude any time spent replaying the video. This includes live views.
}
}
}
Start sharing on Facebook
If you want to find out more about how to connect your Facebook account and send text, photos, or videos using our public API, check out this guide. Also, we have several integration packages to make things easier.
And of course, let us know if you have any questions.