Skip to content

Instantly share code, notes, and snippets.

@adarsh-chakraborty
Created May 27, 2025 19:03
Show Gist options
  • Save adarsh-chakraborty/4a7cef2a0d71c5cdfb3512f8e3cb8daa to your computer and use it in GitHub Desktop.
Save adarsh-chakraborty/4a7cef2a0d71c5cdfb3512f8e3cb8daa to your computer and use it in GitHub Desktop.

Facebook Lead Generation API Setup

This guide walks you through setting up Facebook Lead Generation API integration for your application.

Prerequisites

  • Facebook App with Lead Generation permissions
  • Page Admin access to the Facebook Page
  • App ID and App Secret from your Facebook App

Step-by-Step Setup

1. Generate User Access Token

  1. Navigate to Facebook Graph API Explorer
  2. Generate a User access token with permissions for Page + App

2. Get Page Access Token

Make a GET request to retrieve your page access token:

GET /me/accounts

Copy the Page Access Token and Page ID from the response.

3. Subscribe App to Page

Subscribe your app to the page for lead generation events:

POST /PAGEID/subscribed_apps?access_token={TOKEN}&subscribed_fields=leadgen

Replace:

  • PAGEID with your Page ID
  • {TOKEN} with your Page Access Token

4. Verify Subscription

Check that your app is properly subscribed:

GET /PAGEID/subscribed_apps

5. Generate Long-Lived Access Token

Convert your short-lived token to a long-lived token for production use:

GET https://graph.facebook.com/v22.0/oauth/access_token?grant_type=fb_exchange_token&client_id={FB_APP_ID}&client_secret={FB_APP_SECRET}&fb_exchange_token={CURRENT_TOKEN}

Replace:

  • {FB_APP_ID} with your Facebook App ID
  • {FB_APP_SECRET} with your Facebook App Secret
  • {CURRENT_TOKEN} with your current access token

Useful Tools

Important Notes

⚠️ Always use long-lived access tokens in production to avoid token expiration issues.

📝 Make sure your app has the necessary permissions for lead generation before proceeding with the setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment