Automated 60-Day Facebook Access Token Generator - n8n Workflow

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.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Users needing a persistent Facebook User Access Token for social media automation or management tasks.

  • Developers configuring backend services that interact with the Facebook Graph API (e.g., posting to Pages).

  • n8n users looking for advanced examples of OAuth implementation using the HTTP Request n8n node and Code n8n node.

Overview

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.

How it Works

This n8n workflow operates as a classic OAuth 2.0 flow initiated by a user accessing a specific URL.


  1. Trigger and Configuration: The process starts when the external user visits the Webhook n8n trigger path (/facebook-login). The Config n8n node immediately loads the required appid, appsecret, and fbredirecturi.

  2. Initial Redirect (False Path): An 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.

  3. Token Exchange (True Path): After the user approves permissions on Facebook, they are redirected back to the n8n trigger URL, now containing the short-lived 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.

  4. Long-Lived Token Generation: The subsequent 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.

  5. Output: Finally, the 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.

Installation Guide

To deploy this n8n workflow and generate your Facebook token, follow these steps:


  1. Import the n8n Template: Import the provided JSON data into your n8n instance as a new workflow.

  2. Facebook App Setup: Create or configure a Facebook Developer App. Navigate to 'Facebook Login' settings and ensure the Valid OAuth Redirect URIs includes your final n8n webhook URL (e.g., https://yourdomain.com/webhook/facebook-login).

  3. Configure Credentials: Edit the Config n8n node and update the placeholder values with your actual Facebook appid, appsecret, and fbredirecturi.

  4. Activate n8n Workflow: Switch the n8n workflow status from 'Inactive' to 'Active' (usually found in the top right corner).

  5. Initiate Flow: To start the authorization process, visit your configured redirect URI in your browser, ensuring you append a login parameter (e.g., https://localhost:5678/webhook/facebook-login?type=login).

  6. Authorization: Complete the Facebook login and authorization steps. The final long-lived token will be displayed in your browser, confirming the success of the n8n template.

Node Details

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.


  • Token / Redirect (Respond to Webhook n8n node): These nodes manage the final response. Redirect sends the user to Facebook's authorization page, while Token displays the final retrieved access_token upon successful completion of the n8n workflow.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
L Hung
L Hung

Featured*