Facebook Posts API
This guide explains how to create, publish, update, and reply to a post on your Facebook Page as the Page, and delete a post using the Pages API from Meta.
Before you start
This guide assumes you have read the Overview.
For a person who can perform tasks on the Page, you will need to implement Facebook Login to ask for the following permissions and receive a Page access token:
pages_manage_engagementpages_manage_postspages_read_engagementpages_read_user_engagementpublish_videopermission, if you are publishing a video to the Page.
Your app user must be able to perform the CREATE_CONTENT, MANAGE, and MODERATE tasks on the Page in the API requests.
If your app users do not own or manage the Page
If the API requests are not initiated by Page owners or managers, your app will need a User access token with the following features:
- Page Public Content Access
When testing an API call, you can include the access_token parameter set to your access token. However, for secure calls from your app, always use the Access Token class.
Publish posts
To publish a post to a Page, send a POST request to the /me/feed endpoint, where page_id is the ID of your Page, with the following parameters:
message: The text for your post.link: Your URL, if you want to post a link.published: Set totrueto publish the post immediately (default) orfalseto publish later.- Include
scheduled_publish_time(ifpublishedis set tofalse) with the date in one of the following formats:- An integer UNIX timestamp (e.g.,
1530432000). - An ISO 8061 timestamp string (e.g.,
2018-09-01T10:15:30+01:00). - Any string parsable by PHP's
strtotime()(e.g.,+2 weeks,tomorrow).
- An integer UNIX timestamp (e.g.,
Notes about scheduled posts
- The publish date must be between 10 minutes and 30 days from the time of the API request.
- If relying on
strtotime()'s relative date strings, you can read-after-write thescheduled_publish_timeof the created post to verify it.
Example Request
Formatted for readability. Replace page_id and other placeholders like your_message_text with your actual values.
Example Response
On success, your app receives the following JSON response with the ID of the post:
{
"id": "page_post_id"
}
Add audience targeting
To limit who can see a Page post, you can add the targeting.geo_locations object or the feed_targeting.geo_locations parameter in your POST request.
{
"targeting": {
"geo_locations": {
"countries": ["CA"],
"cities": [
{
"key": "296875",
"name": "Toronto"
}
]
}
}
}
Troubleshooting
In some cases, using both a country and a region within that country will result in the following error:
"Some of your locations overlap. Try removing a location."
In these cases, target either the region or the country, depending on the coverage you need.
Publish Media Posts
You can publish photos and videos to a Page.
Publish a photo
To publish a photo to a Page, send a POST request to the /page_id/photos endpoint, where page_id is the ID of your Page, with the url parameter set to the photo URL.
Example Request
Example Response
On success, your app receives the following JSON response with the ID of the photo and the post:
{
"id": "photo_id",
"post_id": "page_post_id"
}
Publish a video
Please visit the Video API documentation to publish a video post to your Page.
Get Posts
To get a list of Page posts, send a GET request to the /me/feed endpoint.
Example Request
Example Response
On success, your app receives the following JSON response, which includes an array of objects with details of each post on your Page:
{
"data": [
{
"created_time": "2019-01-02T18:31:28+0000",
"message": "This is my test post on my Page.",
"id": "page_post_id"
}
]
}
Limitations
Live Videos
If a Page post contains a video that has expired, such as a live broadcast, you can get some post fields but not fields related to the video. The video has its own privacy rules. If the video has expired, you must be the Page admin to view its information.
Message CTA
Any access token can be used to request publicly shared Page posts as long as your app has been approved for the Page Public Content Access Feature. However, posts with message CTAs cannot be accessed using another Page's access token since pages cannot message other pages.
Page Post URLs
The URL, or permalink, for a Page post is:
https://www.facebook.com/page_post_id
Update a Post
To update a Page post, send a POST request to the /page_post_id endpoint with the parameters you want to update set to the new content.
Example Request
Formatted for readability. Replace italicized values, such as page_post_id, with your values.
Successful Response
On success, your app receives the following JSON response with success set to true:
{
"success": true
}
Limitations
An app can only update a Page post if the post was made using that app.
Delete a Post
To delete a Page post, send a DELETE request to the /page_post_id endpoint where page_post_id is the ID of the post you want to delete.
Example Request
Formatted for readability. Replace italicized values, such as page_post_id, with your values.
Successful Response
On success, your app receives the following JSON response with success set to true:
{
"success": true
}
Next Steps
- Learn how to comment on Page posts and @mention a specific person or Page who posted or commented on your Page.