Skip to content

prashantBtesting/Linkdin-Automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– LinkedIn AI Auto-Poster

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.


✨ What It Does

πŸ” Research         β†’     ✍️ Write Post      β†’     🎨 Generate Image     β†’     πŸš€ Post to LinkedIn
RSS + Google News        Groq (Llama 3.3)         Google Gemini Free           LinkedIn API
    (Free)                   (Free)                     (Free)                    (Free)
  1. Researches trending Tech & AI headlines from 6 major RSS feeds
  2. Writes an engaging LinkedIn post using Groq AI (Llama 3.3 70B)
  3. Generates a professional matching image using Google Gemini
  4. Posts everything automatically to your LinkedIn profile
  5. Logs every post to a local file for your records

πŸ’° Cost

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

πŸ“ Project Structure

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

πŸš€ Complete Setup Guide (Start to Finish)

Follow every step carefully. Takes about 15 minutes total.


STEP 1 β€” Clone the Repository

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-autoposter

STEP 2 β€” Install Python

Make sure you have Python 3.10 or higher installed.

Check your version:

python --version
# or
python3 --version

If not installed:


STEP 3 β€” Install Dependencies

pip install -r requirements.txt

This installs: groq, google-generativeai, requests, python-dotenv, feedparser, Pillow


STEP 4 β€” Get Your API Keys (All Free)

You need 4 API keys total. Follow each sub-step below:


4A β€” Groq API Key (Free β€” for AI post writing)

  1. Go to console.groq.com
  2. Sign up with Google or email (free)
  3. Click "API Keys" in the left sidebar
  4. Click "Create API Key" β†’ give it a name β†’ Copy the key
  5. It starts with gsk_...

4B β€” Google Gemini API Key (Free β€” for image generation)

  1. Go to aistudio.google.com/app/apikey
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Select any project β†’ Click "Create API key in existing project"
  5. Copy the key β€” it starts with AIza...

4C β€” LinkedIn Access Token (Free β€” for posting)

This is the most involved step. Follow carefully:

Part 1 β€” Create a LinkedIn Developer App:

  1. Go to linkedin.com/developers/apps/new
  2. Sign in with your LinkedIn account
  3. Fill in:
    • App name: My LinkedIn Poster (anything works)
    • LinkedIn Page: Type Default Company Page for Individual Developer and select it
    • Privacy policy URL: Your LinkedIn profile URL (e.g. https://linkedin.com/in/yourname)
    • Logo: Upload any square image
  4. Check the terms box β†’ Click "Create app"

Part 2 β€” Enable Required Products:

  1. Inside your app, click the "Products" tab
  2. Find "Share on LinkedIn" β†’ Click "Request access" (activates instantly)
  3. Find "Sign In with LinkedIn using OpenID Connect" β†’ Click "Request access" (activates instantly)

Part 3 β€” Get Your Client ID and Add Redirect URL:

  1. Click the "Auth" tab
  2. Copy your Client ID (e.g. 861jixqv7ljy1b)
  3. Copy your Client Secret (e.g. WPL_AP1.xxxxx)
  4. Scroll down to "OAuth 2.0 settings"
  5. Add this redirect URL exactly:
https://oauth.pstmn.io/v1/callback
  1. Click Save

Part 4 β€” Get Your Access Token:

  1. 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
  1. Click "Allow" on the LinkedIn permissions screen

  2. You'll be redirected β€” copy the code=XXXXX value from the URL

  3. 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"
  1. You'll get a response like:
{"access_token":"AQV...long token...","expires_in":5184000,"scope":"openid,profile,w_member_social"}
  1. Copy the access_token value

⚠️ Token expires in ~60 days. Just repeat Part 4 to get a new one when it expires.


4D β€” Get Your LinkedIn Person URN

Run this in Terminal (replace with your actual access token):

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" https://api.linkedin.com/v2/userinfo

You'll get:

{"sub":"abc123XYZ","name":"Your Name",...}

Your Person URN is: urn:li:person:abc123XYZ (use the sub value)


STEP 5 β€” Configure Your .env File

Create a file called .env in the project root folder:

cp .env.example .env

Open .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 .env file to GitHub. It's already in .gitignore.


STEP 6 β€” Run Your First Post (Special Intro Post)

This script posts a special first post explaining your automation to your audience:

python first_post.py

What 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

STEP 7 β€” Run Daily Automation

From now on, run this every day for a fresh AI-researched post:

python linkedin_auto_post.py

STEP 8 β€” Schedule It (Optional β€” Runs Automatically)

Mac / 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>&1

Windows (Task Scheduler):

  1. Open Task Scheduler β†’ Create Basic Task
  2. Trigger: Daily at 9:00 AM
  3. Action: Start a program β†’ python
  4. Arguments: C:\path\to\linkedin_auto_post.py
  5. Start in: C:\path\to\linkedin-ai-autoposter

πŸ”§ Customisation

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

πŸ› οΈ Troubleshooting

ModuleNotFoundError

pip install -r requirements.txt

Missing 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.


πŸ“Š How the Daily Script Works

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

πŸ”‘ API Keys Summary

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

⭐ If This Helped You

  • Give this repo a star ⭐
  • Share your first automated post and tag me!
  • Open an issue if you hit any problems

πŸ“„ License

MIT License β€” free to use, modify and share.


Built with ❀️ using Groq, Google Gemini and LinkedIn API

About

This is a Linkdin AUtomation Repo with the help of this you can automaticlaly create and upload post on linkdin in Tech & AI Niche

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors