How to Publish Stories with the Facebook Stories API

[ad_1]
Facebook Stories is one of the most popular ways to publish videos, or photos on Facebook, second in popularity only to Facebook Reels. Facebook has been adding a lot of new features to their API and we’re glad they recently released the ability to post Stories using the Meta Graph API. We have been waiting for this announcement since the Instagram Stories API is already there.
Let’s explore and learn how to publish using the new Facebook Stories API.
What is Facebook News?
Facebook Stories has emerged as a compelling way to share moments and messages with friends, family, and fans. But what exactly is a Facebook Story, and why should you consider publishing it?
Facebook Stories are short, ephemeral posts that disappear after 24 hours, reminding anyone of, ahem Snapchat. Built on top of the Facebook timeline, these snippets provide a quick and casual way to share updates, information, or thoughts. Unlike standard Facebook posts, Stories are designed for automated and less polished content, making them a unique tool for real-time engagement.
You can publish a Story as an image or as a video. Here is an example of a Facebook Story image:
Using the Facebook Stories API
Once you’re familiar with the Facebook API, adding the Story API is easy. If you’re not yet familiar with the Facebook API, we recommend this guide.
Facebook permissions
You will need to be granted the following Facebook permissions. This will require Meta review and approval, which may take several iterations with the Meta team. Wait a few weeks to a few months.
pages_manage_posts
pages_read_engagement
pages_show_list
- business_management
The business_management permission is a difficult permission to obtain, but you will need it if any of your users are using Meta Business Suite.
Publish Video to News
After you’ve been granted permissions, your users have approved their accounts, and you have an access token, you can begin the process of uploading a Story video.
Step 1: Start a session
The first step is to start a loading session. Here is a Javascript (Node.js) example:
const initData = await fetch(` { method: "POST" }).then(res => res.json());
With the following JSON response:
{
"video_id": "video_id",
"upload_url": "
}
Step 2: Upload the video file with the remote URL
Assuming your video is hosted remotely, you can use i upload_url
field with the URL of your remote to upload the file.
Start by setting the header with your remote URL to file_url
:
{
method: "POST",
headers: {
Authorization: `OAuth ${access_token}`,
file_url: url
}
};
Next, SEND to upload_url
Response from JSON:
const uploadBinaryResponse = await fetch(upload_url, header)
.then((res) => res.json());
JSON response for successful video upload:
{
"status": {
"video_status": "processing",
"uploading_phase": {
"status": "in_progress",
"bytes_transfered": 50002
},
"processing_phase": {
"status": "not_started"
}
"publishing_phase": {
"status": "not_started",
"publish_status": "published",
"publish_time": 234523452
}
}
}
Step 3: Publish the Video to News
Finally you can publish a video to Facebook Stories by setting the upload_phase
to finsh
. And in JavaScript/Node.js:
fetch(` { method: "POST }).then(res => res.json);
If everything worked, you will get the following JSON response:
{
"success": true,
"post_id": 1234
}
After that you can use the post_id
managing posts, getting stats, retrieving post URLs, etc.
Also, you’ll want to check for errors, since we’ve only described how to be happy and not all error cases, which Facebook unfortunately doesn’t document.
Publish a photo in the News
Publishing a photo to News is similar to publishing a video.
Step 1: Upload an image
You will need to use the Facebook Page Photo API endpoint to upload the photo. Pass your remote media URL to the bottom of the images:
fetch(` { method: "POST" }).then(res => res.json());
The answer will contain a photo_id
which can be sent to the final publication:
fetch(` { method: "POST }).then(res => res.json());
If successful, the following JSON will be returned:
{
"success": true,
"post_id": 1234
}
Easy Way to Facebook News via API
A simple and easy way to use the Facebook Stories API is to use the Ayrshare Social Media API. You can use our Story API to publish video or photos by adding a single field: stories: true
For example, here’s how you can post a FB story:
{
"post": "The description of the video",
"platforms": ["facebook"],
"mediaUrls": ["
"faceBookOptions": {
"stories": true
}
}
It’s that simple! You can also post to Instagram Stories via the API.
If you want more information, see our Business Plan.