Get long-lived Facebook Page access tokens and subscribe Messenger webhook fields via Graph API
Get Long-Lived Facebook Page Access Token and Subscribe Messenger Webhook Fields This n8n template automates two critical one-time setup steps required before any Facebook automation can go live: it exchanges a short-...
Template notes
Get Long-Lived Facebook Page Access Token and Subscribe Messenger Webhook Fields
This n8n template automates two critical one-time setup steps required before any Facebook automation can go live: it exchanges a short-lived User Access Token for a long-lived one (~60 days), retrieves Page Access Tokens for all connected Facebook Pages, and subscribes each Page to the webhook fields your app needs — all in a single manual run.
If you're building a Messenger chatbot or automating comment replies on Facebook Pages, run this utility workflow once as part of your initial setup.
How it works
Needed Value node: Set your appid, appsecret, short-lived shortuseraccesstoken, and fieldtoadd (the webhook subscription fields) in one place — no other node needs editing. Token Exchange: Calls the Facebook Graph API to exchange the short-lived token for a long-lived User Access Token, then resolves the app-scoped User ID. Page Token Retrieval: Fetches long-lived Page Access Tokens for all Pages connected to this user. Per-Page Webhook Subscription: Loops through each Page — fetches its existing subscribed fields, merges them with your new fields, and POSTs the combined list back to the Graph API. Rate Limiting: A 1-second Wait node between each Page prevents hitting Facebook's API rate limits.
How to use
1. Get credentials: Retrieve your App ID and App Secret from [Meta for Developers](https://developers.facebook.com/apps/). 2. Generate a short-lived token: Use [Graph API Explorer](https://developers.facebook.com/tools/explorer/) with pagesmanagemetadata and pagesshowlist permissions. 3. Fill in Needed Value: Enter all four config fields. Set fieldtoadd based on your use case (e.g., messages,messagingpostbacks for Messenger chatbots, or add feed for comment automation). 4. Run manually: Click "Execute Workflow". The output of Get long-lived page access token contains the Page Access Token — copy it into your chatbot workflows.
Requirements