π Automating Facebook Page Posting Using the Meta Graph API (2025 Full Guide)
This guide explains how to automate posting to a Facebook Page using the Meta Graph API, including setup, token generation, posting, deleting posts, and best practices. All sensitive values in this guide use safe placeholders.
π Overview
- Platform: Facebook (Meta)
- API: Graph API v22.0
- Goal: Automate posting to your Facebook Page
- Method: System User (long-lived automation account)
- Difficulty: EasyβModerate
- Best For: Event posting, affiliate posting, alerts, scheduled content, bots
β Requirements
Before you start, you must have:
- Meta Developer App β https://developers.facebook.com
- Meta Business Manager account β required for System User tokens
- A Facebook Page you manage
- A System User added inside Business Manager
- Permissions granted to the System User:
pages_manage_postspages_read_engagementpages_show_listpublic_profile
β Step 1 β Create a System User
- Go to Business Settings β Users β System Users
- Click Add System User
- Choose a name β Role = Admin
- Assign the System User to:
- your Facebook Page
- your Facebook App
This System User is what allows automated posting.
β Step 2 β Generate a System User Token
Inside Business Settings β System Users β Select your system user:
- Click Generate Token
- Select your App
- Enable these scopes:
pages_manage_postspages_read_engagementpages_show_listpublic_profile
You will receive a 60-day renewable System User Token:
1234567890abcdefSYSTEMUSERTOKEN1234567890
π Keep this private β never store in GitHub.
β Step 3 β Get Your Facebook Page ID
Find it in:
Business Settings β Pages β Select Page
Example:
123456789012345
You need this for every API request.
β Step 4 β Fetch Your Page Access Token
Use the System User Token to request a Page Token:
π cURL
curl -X GET \
"https://graph.facebook.com/v22.0/123456789012345?fields=access_token&access_token=1234567890abcdefSYSTEMUSERTOKEN1234567890"
Response:
{
"access_token": "1234567890abcdefPAGEACCESSTOKEN1234567890",
"id": "123456789012345"
}
Save the page_access_token. This is the token you actually use to post.
β Step 5 β Post to the Facebook Page
π cURL Example
curl -X POST "https://graph.facebook.com/v22.0/123456789012345/feed" \
-F "message=π New events are live this week!" \
-F "link=https://yourdomain.com/events" \
-F "access_token=1234567890abcdefPAGEACCESSTOKEN1234567890"
π Python Example
import requests
PAGE_ID = "123456789012345"
PAGE_TOKEN = "1234567890abcdefPAGEACCESSTOKEN1234567890"
def post_to_facebook(message, link=None):
url = f"https://graph.facebook.com/v22.0/{PAGE_ID}/feed"
payload = {
"message": message,
"access_token": PAGE_TOKEN
}
if link:
payload["link"] = link
res = requests.post(url, data=payload)
print(res.json())
post_to_facebook(
message="π£ Don't miss this week's updates!",
link="https://yourdomain.com/events"
)
This automatically generates a clickable preview card.
β Step 6 β Delete a Facebook Post
Every successful post returns an ID like:
123456789012345_987654321098765
π cURL
curl -X DELETE \
"https://graph.facebook.com/v22.0/123456789012345_987654321098765?access_token=1234567890abcdefPAGEACCESSTOKEN1234567890"
π Python
import requests
POST_ID = "123456789012345_987654321098765"
PAGE_TOKEN = "1234567890abcdefPAGEACCESSTOKEN1234567890"
url = f"https://graph.facebook.com/v22.0/{POST_ID}"
res = requests.delete(url, params={"access_token": PAGE_TOKEN})
print(res.json())
β Step 7 β Token Expiration & Refreshing
- Tokens last 60 days
- To renew:
- Generate a new System User Token
- Fetch a new Page Token using the same API call
- Automate renewal every 55 days to be safe
β Step 8 β Security Best Practices
- Store tokens in environment variables (.env files)
- Never commit tokens to GitHub
- Restrict access to servers that run posting scripts
- Use HTTPS links for best preview rendering
β Step 9 β Common Automation Use Cases
- βοΈ Auto-posting events
- βοΈ Affiliate link previews
- βοΈ Scheduled promotions
- βοΈ Auto-sharing blog posts
- βοΈ Marketplace bots
- βοΈ Ticketing websites
- βοΈ Announcement systems
π Final Notes
By using a System User + Page Access Token, you get the most stable, long-lived, automation-friendly way to publish content to Facebook.
If you have questions, spot something that changed in the Meta docs, or just want to share how you're using this setup, feel free to reach out at hello@rmalek.com.