Fully automated LinkedIn posting β Research, Write, Generate Image & Post β 100% Free
This Python script automatically posts to your LinkedIn profile every day. It researches trending Tech & AI topics, writes an engaging post using Groq AI, generates a matching image using Google Gemini, and publishes it to LinkedIn β all with zero manual effort.
This very concept was built and tested live. The first post was written, illustrated and published entirely by this script.
π Research β βοΈ Write Post β π¨ Generate Image β π Post to LinkedIn
RSS + Google News Groq (Llama 3.3) Google Gemini Free LinkedIn API
(Free) (Free) (Free) (Free)
- Researches trending Tech & AI headlines from 6 major RSS feeds
- Writes an engaging LinkedIn post using Groq AI (Llama 3.3 70B)
- Generates a professional matching image using Google Gemini
- Posts everything automatically to your LinkedIn profile
- Logs every post to a local file for your records
| Tool | Cost |
|---|---|
| Groq API (Llama 3.3 70B) | β Free |
| Google Gemini API | β Free tier |
| LinkedIn API | β Free |
| RSS Research | β Free |
| Serper News Search | β Free (2500/month) |
| Total per day | $0 |
linkedin-ai-autoposter/
β
βββ linkedin_auto_post.py # Daily automation script (run this every day)
βββ first_post.py # Special first post script (run once)
βββ requirements.txt # Python dependencies
βββ .env # Your API keys (never commit this!)
βββ .env.example # Example env file (safe to commit)
βββ .gitignore # Ignores .env and outputs/
βββ outputs/ # Generated images + post logs (auto-created)
βββ post_log.jsonl
βββ linkedin_YYYYMMDD_topic.png
Follow every step carefully. Takes about 15 minutes total.
Open Terminal on your Mac/Linux or Command Prompt on Windows:
git clone https://github.com/YOUR_USERNAME/linkedin-ai-autoposter.git
cd linkedin-ai-autoposterMake sure you have Python 3.10 or higher installed.
Check your version:
python --version
# or
python3 --versionIf not installed:
- Download from python.org/downloads
- Install and restart your terminal
pip install -r requirements.txtThis installs: groq, google-generativeai, requests, python-dotenv, feedparser, Pillow
You need 4 API keys total. Follow each sub-step below:
- Go to console.groq.com
- Sign up with Google or email (free)
- Click "API Keys" in the left sidebar
- Click "Create API Key" β give it a name β Copy the key
- It starts with
gsk_...
- Go to aistudio.google.com/app/apikey
- Sign in with your Google account
- Click "Create API Key"
- Select any project β Click "Create API key in existing project"
- Copy the key β it starts with
AIza...
This is the most involved step. Follow carefully:
Part 1 β Create a LinkedIn Developer App:
- Go to linkedin.com/developers/apps/new
- Sign in with your LinkedIn account
- Fill in:
- App name:
My LinkedIn Poster(anything works) - LinkedIn Page: Type
Default Company Page for Individual Developerand select it - Privacy policy URL: Your LinkedIn profile URL (e.g.
https://linkedin.com/in/yourname) - Logo: Upload any square image
- App name:
- Check the terms box β Click "Create app"
Part 2 β Enable Required Products:
- Inside your app, click the "Products" tab
- Find "Share on LinkedIn" β Click "Request access" (activates instantly)
- Find "Sign In with LinkedIn using OpenID Connect" β Click "Request access" (activates instantly)
Part 3 β Get Your Client ID and Add Redirect URL:
- Click the "Auth" tab
- Copy your Client ID (e.g.
861jixqv7ljy1b) - Copy your Client Secret (e.g.
WPL_AP1.xxxxx) - Scroll down to "OAuth 2.0 settings"
- Add this redirect URL exactly:
https://oauth.pstmn.io/v1/callback
- Click Save
Part 4 β Get Your Access Token:
- Paste this URL in your browser (replace
YOUR_CLIENT_ID):
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=https://oauth.pstmn.io/v1/callback&scope=openid%20profile%20w_member_social
-
Click "Allow" on the LinkedIn permissions screen
-
You'll be redirected β copy the
code=XXXXXvalue from the URL -
Run this in Terminal immediately (code expires in ~60 seconds):
curl -X POST "https://www.linkedin.com/oauth/v2/accessToken" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "client_id=YOUR_CLIENT_ID" \
--data-urlencode "client_secret=YOUR_CLIENT_SECRET" \
--data-urlencode "redirect_uri=https://oauth.pstmn.io/v1/callback" \
--data-urlencode "code=YOUR_CODE_HERE"- You'll get a response like:
{"access_token":"AQV...long token...","expires_in":5184000,"scope":"openid,profile,w_member_social"}- Copy the
access_tokenvalue
β οΈ Token expires in ~60 days. Just repeat Part 4 to get a new one when it expires.
Run this in Terminal (replace with your actual access token):
curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" https://api.linkedin.com/v2/userinfoYou'll get:
{"sub":"abc123XYZ","name":"Your Name",...}Your Person URN is: urn:li:person:abc123XYZ (use the sub value)
Create a file called .env in the project root folder:
cp .env.example .envOpen .env and fill in all your keys:
GROQ_API_KEY=gsk_your_groq_key_here
GEMINI_API_KEY=AIza_your_gemini_key_here
LINKEDIN_ACCESS_TOKEN=AQV_your_linkedin_token_here
LINKEDIN_PERSON_URN=urn:li:person:your_id_here
SERPER_API_KEY=your_serper_key_here_or_leave_emptyπ Never commit your
.envfile to GitHub. It's already in.gitignore.
This script posts a special first post explaining your automation to your audience:
python first_post.pyWhat it posts:
- Explains you built a fully automated LinkedIn AI posting system
- Lists the tools used (Groq, Gemini, LinkedIn API)
- Asks people to comment "AI" if they want the repo link
- Drives massive engagement and authenticity
From now on, run this every day for a fresh AI-researched post:
python linkedin_auto_post.pyMac / Linux (cron):
# Open crontab
crontab -e
# Add this line to run every day at 9:00 AM
0 9 * * * cd /full/path/to/linkedin-ai-autoposter && python linkedin_auto_post.py >> outputs/cron.log 2>&1Windows (Task Scheduler):
- Open Task Scheduler β Create Basic Task
- Trigger: Daily at 9:00 AM
- Action: Start a program β
python - Arguments:
C:\path\to\linkedin_auto_post.py - Start in:
C:\path\to\linkedin-ai-autoposter
| What to change | Where to change it |
|---|---|
| Post topic / niche | Edit the system prompt in generate_linkedin_post() |
| Add more RSS feeds | Add URLs to the RSS_FEEDS list |
| Post length | Edit word count in the system prompt |
| Image style | Edit image_prompt instructions in the system prompt |
| Posting time | Change the cron schedule |
| Post to Company Page | Change LINKEDIN_PERSON_URN to urn:li:organization:XXXXX |
ModuleNotFoundError
pip install -r requirements.txtMissing env vars error
Make sure your .env file exists and all 4 keys are filled in.
LinkedIn 401 Unauthorized
Your access token expired (lasts ~60 days). Repeat Step 4C Part 4 to get a new one.
LinkedIn 422 Unprocessable
Scope issue β make sure both Products are enabled in your LinkedIn app (Step 4C Part 2).
Gemini image fails The script automatically falls back to Pollinations AI (100% free, no key needed). Post will still go through with an image.
invalid_client on curl
Use --data-urlencode instead of -d for the curl command β special characters in the client secret can cause this.
1. fetch_rss_headlines() β Pull latest headlines from 6 RSS feeds
2. search_trending_topics() β Optional Google News via Serper API
3. gather_research() β Combine into a research brief
4. generate_linkedin_post() β Groq AI writes post + image prompt + hashtags
5. generate_image_gemini() β Gemini generates matching image
6. upload_image_to_linkedin()β Upload image asset to LinkedIn
7. post_to_linkedin() β Publish post via LinkedIn UGC API
8. save_log() β Record to outputs/post_log.jsonl
| Key | Where to get | Free? |
|---|---|---|
GROQ_API_KEY |
console.groq.com | β Yes |
GEMINI_API_KEY |
aistudio.google.com | β Yes |
LINKEDIN_ACCESS_TOKEN |
Via OAuth (see Step 4C) | β Yes |
LINKEDIN_PERSON_URN |
Via /v2/userinfo API call |
β Yes |
SERPER_API_KEY |
serper.dev | β 2500/month free |
- Give this repo a star β
- Share your first automated post and tag me!
- Open an issue if you hit any problems
MIT License β free to use, modify and share.
Built with β€οΈ using Groq, Google Gemini and LinkedIn API