Skip to main content

Generate viral Facebook posts with Gemini 2.0 & AI image generation

Workflow preview

Workflow preview
100%
Generate viral Facebook posts with Gemini 2.0 & AI image generation preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

AI Facebook Post Generator Complete Setup Guide Transform your content ideas into viral Facebook posts with AI powered automation in just 30 minutes! Prerequisites Checklist What you'll ...

Best for

  • Social Media automation workflows
  • Multimodal AI automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.if, n8n-nodes-base.merge, n8n-nodes-base.facebookgraphapi, n8n-nodes-base.function, n8n-nodes-base.googlesheets, @n8n/n8n-nodes-langchain.chainllm, n8n-nodes-base.code, @n8n/n8n-nodes-langchain.lmchatgooglegemini

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Charles.

Original n8n.io source

1.1 Workflow description

Title
Generate viral Facebook posts with Gemini 2.0 & AI image generation
Workflow name
Generate viral Facebook posts with Gemini 2.0 & AI image generation

πŸš€ AI Facebook Post Generator - Complete Setup Guide

> Transform your content ideas into viral Facebook posts with AI-powered automation in just 30 minutes!


πŸ“‹ Prerequisites Checklist

What you'll need before we start:

  • βœ… n8n instance (cloud or self-hosted)
  • βœ… Facebook Business Page (not personal profile)
  • βœ… Google account with Sheets & Gmail access
  • βœ… Basic understanding of API credentials

⏱️ Estimated Setup Time: 30-45 minutes
🎯 Difficulty Level: Intermediate
πŸ’° Cost: Free tier available for all services


🎨 What You'll Build

By the end of this guide, you'll have:

  • πŸ“ Smart Content Form - Web form that captures your ideas
  • πŸ€– AI Content Optimizer - Gemini AI that polishes your writing
  • πŸ–ΌοΈ Auto Image Generator - Custom visuals created automatically
  • πŸ“Š Content Tracker - Google Sheets logging for analytics
  • πŸ“± Facebook Publisher - Direct posting to your page
  • πŸ“§ Success Notifications - Email confirmations with post links

πŸ”§ Step-by-Step Setup

Step 1: πŸ“˜ Facebook Integration Setup

πŸ”Έ 1.1 Create Your Facebook App

Why this matters: This gives your workflow permission to post on your behalf.

  1. Navigate to Facebook Developers 🌐
  2. Click "My Apps" β†’ "Create App"
  3. Select "Business" as your app type
  4. App Name: AI-Content-Poster (or your preferred name)
  5. Hit "Create App"

> πŸ’‘ Pro Tip: Choose a descriptive name - you'll see this in your Facebook activity logs

πŸ”Έ 1.2 Configure App Settings

  1. In your app dashboard: "Add a Product"
  2. Find "Facebook Login" β†’ "Set Up"
  3. Navigate to Settings β†’ Basic
  4. App Domains: Add app.n8n.cloud (for n8n cloud users)
  5. Save changes βœ…

πŸ”Έ 1.3 Generate Your Page Access Token

This is the key that unlocks posting powers! πŸ”‘

  1. Go to Tools β†’ Graph API Explorer
  2. Select your newly created app
  3. Click "Generate Access Token"
  4. Required Permissions:
    • pages_manage_posts
    • pages_read_engagement
    • pages_show_list
  5. Select your target Facebook page
  6. Copy the token (starts with EAAG...)

⚠️ Critical Step - Make Token Long-Lived:

  • In Graph API Explorer, make a GET request to:
/oauth/access_token?grant_type=fb_exchange_token&client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&fb_exchange_token=YOUR_SHORT_TOKEN

πŸ”Έ 1.4 Find Your Page ID

Two methods to get your Page ID:

Method 1 - Direct from Facebook:

  1. Visit your Facebook page
  2. Click "About" tab
  3. Scroll to find "Page ID"

Method 2 - API Explorer:

  1. Use Graph API Explorer
  2. GET request to: /me/accounts
  3. Find your page in the response

Step 2: πŸ” Google Services Setup

πŸ”Έ 2.1 Enable Required APIs

Setting up your Google Cloud foundation:

  1. Visit Google Cloud Console ☁️
  2. Create new project or select existing
  3. "APIs & Services" β†’ "Library"
  4. Enable these APIs:
    • βœ… Google Sheets API
    • βœ… Gmail API
    • βœ… Google Drive API (optional)

πŸ”Έ 2.2 Create Service Account

This creates a "robot" account for automated access:

  1. "APIs & Services" β†’ "Credentials"
  2. "Create Credentials" β†’ "Service Account"
  3. Name: ai-facebook-automation
  4. "Create and Continue"
  5. Skip role assignment β†’ "Continue"
  6. "Done" βœ…

πŸ”Έ 2.3 Download Credentials File

  1. Click your service account email
  2. "Keys" tab β†’ "Add Key" β†’ "Create New Key"
  3. Choose "JSON" format
  4. Download and save securely πŸ“

> πŸ”’ Security Note: This file contains sensitive credentials. Store it safely!

πŸ”Έ 2.4 Prepare Your Google Sheets

Create your data tracking system:

πŸ“Š Sheet 1: Content Log

  • Purpose: Track all generated content
  • Columns:
    • A: Date (NgΓ y)
    • B: Short Content (Nα»™i dung ngαΊ―n)
    • C: Full Content (Nα»™i dung Δ‘αΊ§y Δ‘α»§)

πŸ“ Sheet 2: Input Tracking

  • Purpose: Log form submissions
  • Columns:
    • A: Date
    • B: Time
    • C: Content

πŸ”— Important: Share both sheets with your service account email (found in the JSON file)


Step 3: πŸ€– AI Services Configuration

πŸ”Έ 3.1 Get Your Gemini API Key

Power up your AI content generation:

  1. Head to Google AI Studio 🎨
  2. Sign in with Google account
  3. "Create API Key"
  4. Copy the key (starts with AIza...)

> πŸ’° Cost Info: Gemini offers generous free tier limits - perfect for getting started!


Step 4: βš™οΈ n8n Workflow Configuration

πŸ”Έ 4.1 Import the Magic ✨

  1. Copy the workflow JSON from the template
  2. In n8n: "Import from JSON"
  3. Paste the workflow code
  4. "Import" to load your new automation

πŸ”Έ 4.2 Configure Your Credentials

πŸ”‘ Facebook Graph API Setup:

  1. Settings β†’ Credentials β†’ "Add Credential"
  2. Search: "Facebook Graph API"
  3. Access Token: Your Page Access Token from Step 1.3
  4. Test connection β†’ Save as: Facebook Page Access

πŸ” Google Services Setup:

  1. "Add Credential" β†’ "Google Service Account"
  2. Upload your JSON file from Step 2.3
  3. Test connection β†’ Save as: Google Services

🧠 Gemini AI Setup:

  1. "Add Credential" β†’ "Google PaLM API"
  2. Enter your Gemini key from Step 3.1
  3. Save as: Gemini AI

πŸ”Έ 4.3 Customize Node Settings

πŸ“± Update Facebook Configuration:

In "Facebook Graph API" node:

  • Replace "113732581629527" with your Page ID from Step 1.4

In "Facebook Upload Img" node:

  • Replace "113732581629527" with your Page ID from Step 1.4

πŸ“Š Update Google Sheets:

In "save content" node:

  • Replace Document ID with your Content Log Sheet ID

In "Append row in sheet" node:

  • Replace Document ID with your Input Tracking Sheet ID

> πŸ’‘ Finding Sheet ID: It's the long string in your Google Sheets URL after /spreadsheets/d/

πŸ“§ Update Notification Email:

In "Send a message" node:


Step 5: πŸ§ͺ Testing & Validation

πŸ”Έ 5.1 Component Testing

πŸ“Š Test Google Sheets Connection:

  1. Right-click "Append row in sheet" node
  2. "Execute Node"
  3. βœ… Verify test row appears in your sheet

πŸ€– Test Gemini AI:

  1. Right-click "Basic LLM Chain" node
  2. "Edit Input Data" β†’ Add test content
  3. Execute β†’ βœ… Verify AI response quality

πŸ–ΌοΈ Test Image Generation:

  1. Right-click "HTTP Request" node
  2. Ensure valid prompt from previous step
  3. Execute β†’ βœ… Check for base64 image data

πŸ“± Test Facebook Upload:

  1. Run full workflow with test content
  2. βœ… Check your Facebook page for new post
  3. βœ… Verify image uploaded correctly

πŸ”Έ 5.2 End-to-End Victory Test πŸŽ‰

  1. "Execute Workflow" on trigger node
  2. Submit test content through the form
  3. Monitor each node execution
  4. 🎊 Celebrate your first AI-generated post!

🎯 Success Indicators

Your setup is complete when you see:

  • βœ… Form accepts and processes content
  • βœ… AI generates optimized text + image prompt
  • βœ… Custom image appears in Facebook post
  • βœ… Content logged in Google Sheets
  • βœ… Success email in your inbox
  • βœ… Professional-looking post on your Facebook page

🚨 Troubleshooting Quick Fixes

Facebook Issues

  • Token Expired? β†’ Generate new long-lived token
  • Permission Denied? β†’ Check page admin rights
  • Invalid Page ID? β†’ Double-check Page ID format

Google Sheets Problems

  • 403 Forbidden? β†’ Share sheet with service account
  • Sheet Not Found? β†’ Verify Sheet ID in URL
  • Column Errors? β†’ Match exact column names

AI Content Issues

  • Empty Responses? β†’ Check Gemini API quotas
  • Poor Quality? β†’ Adjust AI prompts
  • JSON Errors? β†’ Validate parsing logic

🎨 Customization Ideas

Make it uniquely yours:

  • 🎨 Brand Voice: Adjust AI prompts for your tone
  • ⏰ Scheduling: Add time delays for strategic posting
  • πŸ“ˆ Analytics: Connect performance tracking tools
  • πŸ”„ Multi-Platform: Extend to Instagram, LinkedIn
  • πŸ‘₯ Team Features: Add approval workflows

πŸŽ‰ You Did It!

Congratulations! You've built an AI-powered content machine that will save you hours every week.

What's Next?

  • Test with different content types
  • Monitor performance in Google Sheets
  • Refine AI prompts for better results
  • Share your success with the community!

Need Help? 🀝


Ready to revolutionize your content creation? Your AI assistant is waiting! πŸš€

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - If2

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 2 - If1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 3 - Merge

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.1

Block 4 - Facebook Graph API

Type / Role
n8n-nodes-base.facebookGraphApi - facebookGraphApi
Config choices
Version 1

Block 5 - Facebook Upload Img

Type / Role
n8n-nodes-base.facebookGraphApi - facebookGraphApi
Config choices
Version 1

Block 6 - If

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 7 - Format Content

Type / Role
n8n-nodes-base.function - function
Config choices
Version 1

Block 8 - save content

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.5

Block 9 - Basic LLM Chain

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.6

Block 10 - Basic LLM Chain1

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.6

Block 11 - Convert to File code

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 12 - Google Gemini Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 13 - Google Gemini Chat Model1

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 14 - code2

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 15 - HTTP Request

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 16 - On form submission1

Type / Role
n8n-nodes-base.formTrigger - formTrigger
Config choices
Version 2.2

Block 17 - Append row in sheet

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.5

Block 18 - Send a message

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 19 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 20 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 21 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 22 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow Generate viral Facebook posts with Gemini 2.0 & AI image generation
Complexity advanced
Nodes 22
Categories Social Media, Multimodal AI
Author Charles
Published 19 Sept 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/8756/8756.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Generate viral Facebook posts with Gemini 2.0 & AI image generation do?

AI Facebook Post Generator Complete Setup Guide Transform your content ideas into viral Facebook posts with AI powered automation in just 30 minutes! Prerequisites Checklist What you'll ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Social Media, Multimodal AI use case.