Prerequisites

  • A registered Facebook Developer App
  • Administrative access to a Facebook Page
  • Access to the Graph API Explorer and Access Token Debugger tools

Step-by-Step Implementation

Step 1: Generate Short-Lived User Access Token

  1. Navigate to the Graph API Explorer tool.
  2. Select your target developer application from the top-right menu.
  3. Select Get User Access Token.
  4. Enable the following permissions:
    • pages_show_list
    • pages_read_engagement
    • pages_manage_posts
    • instagram_basic (optional)
    • instagram_content_publish (optional)
  5. Click Generate Access Token to produce a short-lived token valid for 1 hour.

Step 2: Exchange for Long-Lived User Access Token

  1. Copy the generated short-lived user token.
  2. Open the Access Token Debugger tool.
  3. Paste the string and click Debug.
  4. Select Extend Access Token and authenticate if prompted.
  5. Copy the resulting long-lived user token, which remains valid for approximately 60 days.

Step 3: Generate Permanent Page Access Token

  1. Return to the Graph API Explorer.
  2. Insert the long-lived user token into the Access Token field.
  3. Execute a GET request to the endpoint: PAGE_ID?fields=access_token (replacing PAGE_ID with your numeric target Page ID).

The access_token string returned in this JSON object acts as the non-expiring page access token.

Step 4: Verify Expiration Status

  1. Paste the newly acquired page access token into the Access Token Debugger.
  2. Click Debug and ensure that the Expires metadata field explicitly states Never.

Python Automation Implementation

Use the permanent page access token in requests targeting the Graph API endpoint:

Troubleshooting & Error Handling

Error Code / Message Root Cause & Resolution
(#200) Permissions error Missing granular scopes. Regenerate the initial token ensuring pages_manage_posts and pages_read_engagement are explicitly granted.
Invalid or expired token The short-lived parent token expired prior to extension. Restart the token exchange process.
No access_token in response The request was executed using an App Access Token instead of an extended User Access Token.

Operational Guidelines

  • Page access tokens function strictly for the specific Page ID requested during generation.
  • Instagram Content Publishing requires linking the target Instagram Business account to the corresponding Facebook Page before token generation.
  • System access tokens should be stored securely in environment variables rather than hardcoded in application repositories.