Use this robust n8n workflow template to automatically generate and manage 60-day long-lived Facebook Access Tokens via the OAuth flow, essential for continuous social media automation.
Download this n8n workflow template and start using it instantly.
Managing OAuth tokens, especially those that expire frequently, is a common hurdle in social media automation. This sophisticated n8n workflow solves this by streamlining the entire Facebook authorization process, from initial redirect to final long-lived token generation. By using this n8n template, users can reliably obtain a robust 60-day token, minimizing service interruptions caused by token expiration. The process involves two critical HTTP requests chained together to exchange the short-lived authorization code for the necessary long-lived access token, ensuring your automated tasks remain active and secure. This specific n8n workflow also includes extensive instructions via sticky notes on how to set up the corresponding Facebook App and retrieve subsequent Page Tokens.
This n8n workflow operates as a classic OAuth 2.0 flow initiated by a user accessing a specific URL.
/facebook-login). The Config n8n node immediately loads the required appid, appsecret, and fbredirecturi.If n8n node checks if the request includes a Facebook authorization code. If not (the initial entry), the flow proceeds to the Redirect URL Code n8n node. This node dynamically builds the full Facebook OAuth URL, embedding the app details and the required scopes (like pagesmanageposts). The Redirect n8n node then instructs the user's browser to go to this Facebook login page.code in the query parameters. The If n8n node directs the flow to the Short-Lived Token HTTP Request n8n node. This n8n node exchanges the code for an initial short-term access token.Long-Lived Token n8n node takes this short-term token and performs a second exchange (using fbexchangetoken grant type) to obtain the robust, 60-day token.Token n8n node (Respond to Webhook) displays the generated long-lived access token directly to the user, concluding the successful execution of this automated n8n workflow.To deploy this n8n workflow and generate your Facebook token, follow these steps:
https://yourdomain.com/webhook/facebook-login).Config n8n node and update the placeholder values with your actual Facebook appid, appsecret, and fbredirecturi.https://localhost:5678/webhook/facebook-login?type=login). Webhook (n8n trigger): The entry point, listening on the path /facebook-login. It is configured to utilize a response node (responseNode).
Config (Set n8n node): Essential for storing application secrets (appid, appsecret) and the fbredirecturi. These values are dynamically used throughout the n8n workflow.
If (n8n node): Handles flow control by checking if the query parameter code is present. This determines whether the workflow is starting the redirect (False) or exchanging the token (True).
Redirect URL (Code n8n node): Used on the False path. It uses JavaScript to construct the initial Facebook OAuth URL, generating a random state and listing all required permissions (correctScopes), which are joined into a scope string for the n8n trigger URL.
Short-Lived Token (HTTP Request n8n node): On the True path, this n8n node sends a GET request to the Facebook API to exchange the received authorization code for a short-lived access token.
Long-Lived Token (HTTP Request n8n node): Takes the output of the previous n8n node and performs the necessary API call to upgrade the temporary token to a 60-day long-lived token.
Redirect sends the user to Facebook's authorization page, while Token displays the final retrieved access_token upon successful completion of the n8n workflow.Build an advanced, bilingual customer support chatbot using an n8n workflow. This automation utilizes OpenAI agents for quick responses via the Facebook Messenger n8n node, smart classification, and seamless human agent escalation for complex queries. Deploy this powerful n8n workflow today.

Build a robust Facebook Messenger AI bot using this n8n workflow. It supports text, image, and voice transcription via GPT-4, featuring tools, memory, and automated response formatting.

Use this comprehensive n8n workflow to capture Facebook Lead Ad submissions, save them to Google Sheets, and automate personalized email follow-ups using the Gmail n8n node.

Use this powerful n8n workflow to securely send hashed eCommerce Purchase or Lead events to the Meta Conversion API, ensuring privacy compliance and accurate ad attribution.

Automate daily family routines, meal planning, and communication reminders using this comprehensive n8n workflow. Schedule reminders for events, bedtime, and weekly planning via email and Telegram.









































