How To Automate Your Social Media with AI + n8n?

Tired of manually posting on social media every day? Want to grow your audience while you sleep? In this guide, I’ll show you how to create an AI-powered social media agent that automatically posts trending news to LinkedIn and Facebook—for free using n8n (a no-code automation tool).

How It Works

  1. Fetches Latest News – Uses the GNews API to find trending articles.
  2. Generates AI Content – Google Gemini rewrites the news into engaging posts.
  3. Creates AI Images – Automatically generates visuals for each post.
  4. Auto-Posts to Social Media – Publishes to LinkedIn & Facebook on a schedule.

What You’ll Need

✅ Free n8n account
✅ Free Google Gemini API Key
✅ Free GNews API Key
✅ Facebook & LinkedIn developer access (for auto-posting)


Step 1: Set Up the n8n Workflow

  1. Go to n8n.io and sign up (or use the desktop app).
  2. Create a new workflow (click the + button).
  3. Add a Schedule Trigger – This will run your workflow daily.
  • Set it to trigger at 9 AM (or your preferred time).

Step 2: Fetch Trending News (GNews API)

  1. Add an HTTP Request Node – This will call the GNews API.
  2. Configure the API Request:
  • Method: GET
  • URL: https://gnews.io/api/v4/top-headlines
  • Query Parameters:
    • token=YOUR_API_KEY (Get it from GNews)
    • q=ecommerce (or any topic like “AI,” “marketing,” etc.)
    • lang=en (for English articles)
    • max=5 (number of articles to fetch)
  1. Test the Node – You should see recent news articles in JSON format.

Step 3: Let AI Pick the Best Article

  1. Add an AI Agent Node (Google Gemini).
  2. Configure Gemini API:
  • Model: Gemini 1.5 Pro
  • Prompt:
    "You are an expert social media strategist. Analyze these articles and pick the one most likely to get engagement. Return the title, URL, and a short summary."
  1. Map the GNews data (title, description, URL) into the AI input.
  2. Test the Node – It should return the best article for posting.

Step 4: Generate AI-Powered Post Content

  1. Add Another AI Agent Node (Gemini).
  2. Prompt:
   "Write a LinkedIn/Facebook post about this news. Make it engaging, add hashtags, and include 'Read more: [URL]' at the end."  
  1. Test the Node – You’ll get a ready-to-post social media update.

Step 5: Create an AI Image for the Post

  1. Add an HTTP Request Node (Gemini Image Generation).
  2. URL: https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent
  3. Headers: Authorization: Bearer YOUR_GEMINI_API_KEY
  4. Body (JSON):
    json { "contents": [{ "parts": [{ "text": "Generate an engaging social media image about: [ARTICLE_SUMMARY]" }] }] }
  5. Test & Extract Image URL – Save the generated image for posting.

Step 6: Auto-Post to Facebook

  1. Add Facebook Graph API Node.
  2. Configure:
  • Endpoint: me/feed (or page_id/feed for Pages).
  • Method: POST
  • Parameters:
    • message = AI-generated post text
    • url = AI-generated image URL
  1. Test the Node – Check your Facebook to confirm the post went live!

Step 7: Auto-Post to LinkedIn

  1. Add LinkedIn API Node.
  2. Configure:
  • Endpoint: ugcPosts
  • Method: POST
  • Body:
    json { "author": "urn:li:person:YOUR_ID", "lifecycleState": "PUBLISHED", "specificContent": { "com.linkedin.ugc.ShareContent": { "shareCommentary": { "text": "AI-generated post here" }, "media": [{ "status": "READY", "description": { "text": "AI-generated image" } }] } }, "visibility": { "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC" } }
  1. Test & Confirm Posting – Refresh LinkedIn to see the automated post!

Step 8: Schedule Daily Auto-Posting

  • Go back to the Schedule Trigger and set it to run daily at your chosen time.
  • Save & Activate the workflow.

🎉 Done! Your AI agent will now:
✔ Fetch trending news
✔ Write posts with AI
✔ Generate images
✔ Post to LinkedIn & Facebook automatically!


Bonus: Expand to Twitter & Instagram

Want to add more platforms? Drop a comment below, and I’ll make a follow-up tutorial!

5/5 - (5 votes)

About

Leave a Comment

Your email address will not be published. Required fields are marked *