If you’re building a Python or automation script to post content on your Facebook Page using the Graph API, you might have noticed that your access token expires in just 1 hour by default. This can interrupt automation and require frequent re-authentication.
In this tutorial, I’ll walk you through how to get a long-lived user access token (valid for ~60 days) and then a permanent page access token (with no expiry). All this using Facebook’s official tools:
- Graph API Explorer
- Access Token Debugger
Prerequisites
- A Facebook Developer App
- A Facebook Page where you're an admin
- Access to Graph API Explorer and Access Token Debugger
Step-by-Step Guide
Step 1: Open Graph API Explorer
- Go to: Graph API Explorer
- Select your app from the top-right dropdown.
- Click on "Get User Access Token".
- Select the following permissions:
pages_show_list
pages_read_engagement
pages_manage_posts
- (Optional)
instagram_basic
,instagram_content_publish
- Click Generate Access Token.
This token will be short-lived (1 hour) by default.
Step 2: Extend the User Access Token (Optional)
- Copy the access token you just generated.
- Go to Access Token Debugger
- Paste the token and click "Debug".
- Click "Extend Access Token" and re-login if asked.
- Copy the new long-lived token (~60 days).
Use this token in API calls if you're not automating long-term. But for permanent automation, continue to the next step.
Step 3: Get the Permanent Page Access Token
- Go back to Graph API Explorer
- Paste your long-lived user token into the Access Token field.
- Make a GET request with this query:
PAGE_ID?fields=access_token
- Replace
PAGE_ID
with your real Page ID.
{
"access_token": "EAAGm0PX4ZCpsBAKZC...",
"id": "YOUR_PAGE_ID"
}
The access_token in this response is your permanent page access token.
Step 4 (Optional): Verify the Page Token
- Go to Access Token Debugger
- Paste your permanent page token.
- Click Debug and verify that "Expires" is Never.
Sample Python Snippet to Use the Token
import requests
PAGE_ACCESS_TOKEN = "EAAGm0PX4ZCpsBAKZC..."
PAGE_ID = "1234567890"
response = requests.post(
f"https://graph.facebook.com/v18.0/{PAGE_ID}/photos",
params={
"url": "https://example.com/image.jpg",
"caption": "🚀 New post from TheVsHub.in!\nCheck it out 👉 example.com/blog",
"access_token": PAGE_ACCESS_TOKEN
}
)
print(response.json())
Final Tips
- Page tokens work only for the page they’re generated for.
- If you're using Instagram API, connect the Instagram account to your Facebook Page.
- Check token expiry using the Access Token Debugger.
Common Issues
Error Message | Solution |
---|---|
(#200) Permissions error |
Make sure required permissions were selected while generating the token. |
Invalid or expired token |
Use an extended token or repeat the process. |
No access_token in response |
Ensure you're querying with a user token, not an app token. |
Useful Links
Wrapping Up
Using this workflow, you can generate a reliable permanent page access token for automation, social media publishing, or AI-based tools.
Need help building an Instagram + Facebook Auto Poster using Python? Follow my tutorials on TheVsHub.in.
Tags:Facebook API, Graph API, Python Automation, Access Token, Facebook Page Token, Instagram API, Social Media Automation, Developer Guide, TheVsHub