How to connect Facebook to n8n?
How to connect Facebook to n8n is simple: create a Facebook App, obtain a long-lived access token, and configure the Facebook node in n8n running on Docker. This guide gives a clear, direct path with commands and configuration examples so you can automate Facebook pages and posts from n8n quickly.
What You Need
- n8n running on Docker (or a server). Node.js knowledge helps for advanced flows.
- A Facebook Developer account and a Facebook App with appropriate permissions.
- A Facebook Page or Instagram Business account to manage via API.
- Basic HTTPS endpoint or domain for webhooks.
How to connect Facebook to n8n: Step-by-step
Follow these steps in order. Each step has the logic you need to finish configuration.
Step 1: Install and start n8n with Docker
Run n8n in Docker. Expose port 5678 and set a secure webhook URL and basic auth. Replace placeholders with your values.
docker run -it --name n8n -p 5678:5678 \
-e N8N_BASIC_AUTH_ACTIVE=true \
-e N8N_BASIC_AUTH_USER="n8nuser" \
-e N8N_BASIC_AUTH_PASSWORD="StrongPass123" \
-e N8N_HOST="your.domain.com" \
-e WEBHOOK_URL="https://your.domain.com/" \
n8nio/n8n:latest
Step 2: Create a Facebook App and get credentials
In developers.facebook.com create a new app. Add the Facebook Login or Pages API product. Note the App ID and App Secret.
- 1. Create app > Choose Business type if managing pages.
- 2. Go to Settings > Basic and copy App ID and App Secret.
- 3. In App Review request pages_read_engagement and pages_manage_posts if needed.
Step 3: Get a user access token and exchange for long-lived token
Use the Graph API explorer or OAuth flow to get a short-lived user token. Exchange it for a long-lived token with this command:
curl -X GET "https://graph.facebook.com/v16.0/oauth/access_token?grant_type=fb_exchange_token&client_id=APP_ID&client_secret=APP_SECRET&fb_exchange_token=SHORT_LIVED_TOKEN"
Record the returned access_token value. That is your long-lived user token.
Step 4: Get a Page access token
Use the long-lived user token to fetch page tokens. Replace LONG_LIVED_TOKEN and APP_VERSION if needed.
curl -X GET "https://graph.facebook.com/v16.0/me/accounts?access_token=LONG_LIVED_TOKEN"
Copy the page access_token for the page you want to manage. Use that token in n8n.
Step 5: Configure the Facebook node in n8n
Open your n8n editor at http://localhost:5678 (or your domain). Add the Facebook node for Pages or Graph API. Set authentication to “Access Token” and paste the Page access_token.
- 1. Create a new workflow.
- 2. Add an HTTP Request node or the Facebook node provided by n8n.
- 3. Set the node to call the Graph API endpoint or the action you need (post, read).
Update
Tokens can expire. Check the Facebook App and tokens every few months. If you need to refresh, repeat the OAuth or token exchange steps. Log webhook failures in n8n to detect expired tokens early.
Security
Keep App Secret and tokens private. Use environment variables with Docker instead of embedding secrets in flows. Enable HTTPS and basic auth for n8n. Limit app permissions to only what you need.
# Example: set token as environment variable in Docker (replace values)
-e FB_PAGE_TOKEN="your_page_token_here"
Rotate tokens if you suspect compromise and remove unused app permissions.
Done
You now have Facebook connected to n8n. You can trigger posts, read page data, and automate responses. Test each flow and monitor logs. Update tokens when needed and follow the security steps above.