1. Setup Environment
python3 -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
pip install requests python-dotenv schedule
2. Create Meta Developer App
- Go to developers.facebook.com → Create App
- Choose Business app type → Add Instagram Graph API
- Get App ID, App Secret, Access Token
3. Link Instagram Account
- Convert IG account to Business/Creator
- Link it to a Facebook Page under Settings → Linked Accounts
4. Store in .env
APP_ID=your_app_id
APP_SECRET=your_app_secret
ACCESS_TOKEN=your_access_token
IG_USER_ID=your_instagram_user_id
IMAGE_URL=https://example.com/image.jpg
CAPTION=Your caption text here
5. Write Python Script
- Load .env
- Upload image to IG Graph API
- Publish with caption
6. Schedule Automation
schedule.every().day.at("10:00").do(job) # Or Cron
7. Test & Deploy
Run manually first, then automate
Welcome to CodeVisium’s Lightning-Fast Automations! 🚀
In this tutorial, we’ll show you how to automate Instagram posts using Python and the Meta Graph API. This is perfect for marketers, creators, and businesses that want to post consistently without doing everything manually.
1. Setup Environment
Create a virtual environment and install the required libraries:
python3 -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
pip install requests python-dotenv schedule
requests → Make API calls to Instagram.
python-dotenv → Securely load credentials from .env.
schedule → Run tasks automatically at specific times.
2. Create a Meta (Facebook) Developer Account
Go to Meta for Developers
.
Create an App → Select Business as the type.
Under Add Products, enable Instagram Graph API.
Copy down your App ID and App Secret.
3. Generate Access Tokens
In App Settings, generate a User Access Token with:
instagram_basic
pages_show_list
instagram_content_publish
Extend it to a Long-Lived Token (valid for ~60 days).
4. Link Instagram Business Account
Go to Instagram → Switch to Business or Creator account.
Link this account to a Facebook Page:
Settings → Linked Accounts → Facebook.
This step is required for the Graph API to post content.
5. Store Credentials in .env
Create a .env file in your project root:
APP_ID=your_app_id_here
APP_SECRET=your_app_secret_here
ACCESS_TOKEN=your_long_lived_token
IG_USER_ID=your_instagram_user_id
IMAGE_URL=https://example.com/sample.jpg
CAPTION=Automated post from CodeVisium 🚀 #Automation #Python
6. Write the Python Script (instagram_auto_post.py)
import os
import requests
from dotenv import load_dotenv
Load environment variables
load_dotenv()
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
IG_USER_ID = os.getenv("IG_USER_ID")
IMAGE_URL = os.getenv("IMAGE_URL")
CAPTION = os.getenv("CAPTION")
Step 1: Upload media
upload_url = f" / v17.0 {IG_USER_ID}/media"
params = {
"image_url": IMAGE_URL,
"caption": CAPTION,
"access_token": ACCESS_TOKEN
}
resp = requests.post(upload_url, params=params).json()
creation_id = resp.get("id")
Step 2: Publish media
publish_url = f" / v17.0 {IG_USER_ID}/media_publish"
publish_params = {
"creation_id": creation_id,
"access_token": ACCESS_TOKEN
}
publish_resp = requests.post(publish_url, params=publish_params).json()
print("Post published:", publish_resp)
✅ Run the script manually → Check if the post appears on Instagram.
7. Schedule the Automation
You can automate daily posts:
import schedule, time
def job():
Run post code here
print("Posting to Instagram...")
schedule.every().day.at("10:00").do(job)
while True:
schedule.run_pending()
time.sleep(30)
Or use Cron (Linux/macOS):
0 10 * * * /usr/bin/python3 /path/to/instagram_auto_post.py
On Windows, use Task Scheduler.
8. Test & Deploy
Test your script manually.
Make sure tokens are valid (refresh long-lived tokens every ~60 days).
Deploy on a server (AWS, Heroku, Railway) for 24/7 automation.
🔑 Use Cases
Digital Marketing Teams → Automate daily promotions.
Creators → Schedule inspirational posts at peak hours.
Businesses → Maintain consistent branding without manual effort.
With this setup, you can auto-post to Instagram, freeing up your time for strategy and creativity. Combine with AI-generated content for next-level automation.
Stay tuned for more tutorials in Lightning-Fast Automations from CodeVisium.
#Automation #Python #Instagram #SocialMedia #MetaAPI #CodeVisium #Productivity #DigitalMarketing
In questa pagina del sito puoi guardare il video online Schedule Instagram Posts with Python & Meta API della durata di ore minuti seconda in buona qualità , che l'utente ha caricato CodeVisium 25 settembre 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,152 volte e gli è piaciuto 6 spettatori. Buona visione!