This guide explains how to create, publish, and update a post, and reply to a post on your Facebook Page as the Page, and delete a post using the Pages API from Meta.
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_posts pages_read_engagement pages_read_user_engagement publish_video permission, if you are publishing a video to the PageYour 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 in the API requests, your app will need a User access token and the following features:
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.
To publish a post to a Page, send a POST request to the /page_id/feed endpoint, where page_id is the ID for your Page, with the following parameters:
message set to the text for your postlink set to your URL if you want to post a linkpublished set to true to publish the post immediately (default) or false to publish later
scheduled_publish_time if set to false with the date in one of the following formats:
1530432000)2018-09-01T10:15:30+01:00)strtotime() (e.g. +2 weeks, tomorrow)strtotime()'s relative date strings you can read-after-write the scheduled_publish_time of the created post to make sure it is what is expected.curl -X POST "https://graph.facebook.com/v24.0/page_id/feed" \
-H "Content-Type: application/json" \
-d '{
"message":"your_message_text",
"link":"your_url",
"published":"false",
"scheduled_publish_time":"unix_time_stamp_of_a_future_date",
}'On success, your app receives the following JSON response with the ID for the post:
{
"id": "page_post_id"
}
To limit who can see a Page post, you can add the targeting.geo_locations object or feed_targeting.geo_locations parameter in your POST request.
-d '{
...
"targeting": {
"geo_locations": {
"countries": [
"CA"
],
"cities": [
{
"key": "296875",
"name": "Toronto"
}
]
}
},
...
}'In some cases using both a country and a region within that country will result in an error: "Some of your locations overlap. Try removing a location." In these cases target the region or the country depending on the coverage you want.
You can publish photos and videos to a Page.
To publish a photo to a Page, send a POST request to the /page_id/photos endpoint, where page_id is the ID for your Page, with the url parameter set to the photo for your post.
curl -X POST "https://graph.facebook.com/v24.0/page_id/photos" \
-H "Content-Type: application/json" \
-d '{
"url":"path_to_photo",
On success, your app receives the following JSON response with the ID for the photo and the ID for the post:
{
"id":"photo_id",
"post_id":"page_post_id"
}
Please visit the Video API documentation to publish a video post to your Page.
To get a list of Page posts, send a GET request to the /page_id/feed endpoint.
curl -i -X GET "https://graph.facebook.com/v24.0/page_id/feed"
On success, your app receives the following JSON response with an array of objects that include the post ID, the time the post was created, and the content for the post, for 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"
}
],
...
}
The URL, or permalink, for a Page post is https://www.facebook.com/page_post_id.
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.
curl -X POST "https://graph.facebook.com/v24.0/page_post_id" \
-H "Content-Type: application/json" \
-d '{
"message":"I am updating my Page post",
}'
On success, your app receives the following JSON response with success set to true:
{
"success": true
}
An app can only update a Page post if the post was made using that app.
To delete a Page post, send a DELETE request to the /page_post_id endpoint where page_post_id is the ID for post you want to delete.
curl -i -X DELETE "https://graph.facebook.com/v24.0/page_post_id"
On success, your app receives the following JSON response with success set to true:
{
"success": true
}
Learn how to comment on Page posts and @mention a specific person or Page who posted or commented on your Page.