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
- Fetches Latest News – Uses the GNews API to find trending articles.
- Generates AI Content – Google Gemini rewrites the news into engaging posts.
- Creates AI Images – Automatically generates visuals for each post.
- 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
- Go to n8n.io and sign up (or use the desktop app).
- Create a new workflow (click the
+
button). - 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)
- Add an HTTP Request Node – This will call the GNews API.
- 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)
- Test the Node – You should see recent news articles in JSON format.
Step 3: Let AI Pick the Best Article
- Add an AI Agent Node (Google Gemini).
- 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."
- Map the GNews data (title, description, URL) into the AI input.
- Test the Node – It should return the best article for posting.
Step 4: Generate AI-Powered Post Content
- Add Another AI Agent Node (Gemini).
- Prompt:
"Write a LinkedIn/Facebook post about this news. Make it engaging, add hashtags, and include 'Read more: [URL]' at the end."
- Test the Node – You’ll get a ready-to-post social media update.
Step 5: Create an AI Image for the Post
- Add an HTTP Request Node (Gemini Image Generation).
- URL:
https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent
- Headers:
Authorization: Bearer YOUR_GEMINI_API_KEY
- Body (JSON):
json { "contents": [{ "parts": [{ "text": "Generate an engaging social media image about: [ARTICLE_SUMMARY]" }] }] }
- Test & Extract Image URL – Save the generated image for posting.
Step 6: Auto-Post to Facebook
- Add Facebook Graph API Node.
- Configure:
- Endpoint:
me/feed
(orpage_id/feed
for Pages). - Method:
POST
- Parameters:
message
= AI-generated post texturl
= AI-generated image URL
- Test the Node – Check your Facebook to confirm the post went live!
Step 7: Auto-Post to LinkedIn
- Add LinkedIn API Node.
- 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" } }
- 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)