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.
Navigate to Facebook Developers π Click "My Apps" β "Create App" Select "Business" as your app type App Name: AI-Content-Poster (or your preferred name) Hit "Create App"
> π‘ Pro Tip: Choose a descriptive name - you'll see this in your Facebook activity logs
πΈ 1.2 Configure App Settings
In your app dashboard: "Add a Product" Find "Facebook Login" β "Set Up" Navigate to Settings β Basic App Domains: Add app.n8n.cloud (for n8n cloud users) Save changes β
πΈ 1.3 Generate Your Page Access Token
This is the key that unlocks posting powers! π
Go to Tools β Graph API Explorer Select your newly created app Click "Generate Access Token" Required Permissions: pages_manage_posts pages_read_engagement pages_show_list Select your target Facebook page 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: Visit your Facebook page Click "About" tab Scroll to find "Page ID"
Method 2 - API Explorer: Use Graph API Explorer GET request to: /me/accounts Find your page in the response
Step 2: π Google Services Setup
πΈ 2.1 Enable Required APIs
Setting up your Google Cloud foundation:
Visit Google Cloud Console βοΈ
Create new project or select existing
"APIs & Services" β "Library"
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:
"APIs & Services" β "Credentials" "Create Credentials" β "Service Account" Name: ai-facebook-automation "Create and Continue" Skip role assignment β "Continue" "Done" β
πΈ 2.3 Download Credentials File
Click your service account email "Keys" tab β "Add Key" β "Create New Key" Choose "JSON" format 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:
Head to Google AI Studio π¨ Sign in with Google account "Create API Key" 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 β¨
Copy the workflow JSON from the template In n8n: "Import from JSON" Paste the workflow code "Import" to load your new automation
πΈ 4.2 Configure Your Credentials
π Facebook Graph API Setup: Settings β Credentials β "Add Credential" Search: "Facebook Graph API" Access Token: Your Page Access Token from Step 1.3 Test connection β Save as: Facebook Page Access
π Google Services Setup: "Add Credential" β "Google Service Account" Upload your JSON file from Step 2.3 Test connection β Save as: Google Services
π§ Gemini AI Setup: "Add Credential" β "Google PaLM API" Enter your Gemini key from Step 3.1 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: Replace xxx@gmail.com with your email address Configure Gmail credentials
Step 5: π§ͺ Testing & Validation
πΈ 5.1 Component Testing
π Test Google Sheets Connection: Right-click "Append row in sheet" node "Execute Node" β Verify test row appears in your sheet
π€ Test Gemini AI: Right-click "Basic LLM Chain" node "Edit Input Data" β Add test content Execute β β Verify AI response quality
πΌοΈ Test Image Generation: Right-click "HTTP Request" node Ensure valid prompt from previous step Execute β β Check for base64 image data
π± Test Facebook Upload: Run full workflow with test content β Check your Facebook page for new post β Verify image uploaded correctly
πΈ 5.2 End-to-End Victory Test π
"Execute Workflow" on trigger node Submit test content through the form Monitor each node execution π 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? π€ Join n8n Discord Visit Community Forum Check n8n Documentation
Ready to revolutionize your content creation? Your AI assistant is waiting! π
Related Templates
Instagram Full Profile Scraper with Apify and Google Sheets
πΈ Instagram Full Profile Scraper with Apify and Google Sheets This n8n workflow automates the process of scraping ful...
Auto-classify Gmail emails with AI and apply labels for inbox organization
Who is this for? Professionals and individuals who receive high volumes of emails, those who want to automatically organ...
Compare Lists and Identify Common Items & Differences Using Custom Keys
This workflow compares two lists of objects (List A and List B) using a user-specified key (e.g. email, id, domain) and ...
π Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments