Creating 50 programmatic videos a day is only half the battle. If an editor still has to manually upload, tag, and publish them to Instagram, TikTok, and YouTube Shorts, your media pipeline remains bottlenecked.
Here is the exact automation stack to publish programmatic MP4 reels directly to Instagram and TikTok using Python.
1. Meta Graph API Reels Upload Pipeline
┌──────────────────┐ 1. POST /media (video_url) ┌──────────────────┐
│ Python Publisher │ ─────────────────────────────────────> │ Meta Graph API │
│ Engine │ <───────────────────────────────────── │ Container ID │
└────────┬─────────┘ Container ID returned └──────────────────┘
│
│ 2. Poll Status until 'FINISHED'
│
▼ 3. POST /media_publish
┌──────────────────┐ ─────────────────────────────────────> 🚀 Published Reel
│ Reel Live on Feed│ <───────────────────────────────────── Live on Account
└──────────────────┘
2. Python Upload Implementation
import time
import requests
def publish_instagram_reel(
page_access_token: str,
ig_user_id: str,
video_cdn_url: str,
caption: str
):
# Step 1: Create Media Container
init_url = f"https://graph.facebook.com/v21.0/{ig_user_id}/media"
payload = {
"media_type": "REELS",
"video_url": video_cdn_url,
"caption": caption,
"access_token": page_access_token,
"share_to_feed": True
}
res = requests.post(init_url, data=payload).json()
creation_id = res.get("id")
if not creation_id:
raise ValueError(f"Failed to create reel container: {res}")
# Step 2: Poll Container Status until Ready
status_url = f"https://graph.facebook.com/v21.0/{creation_id}?fields=status_code&access_token={page_access_token}"
for _ in range(30):
time.sleep(5)
status_res = requests.get(status_url).json()
status_code = status_res.get("status_code")
if status_code == "FINISHED":
break
elif status_code == "ERROR":
raise RuntimeError(f"Meta video processing failed: {status_res}")
# Step 3: Publish the Container
publish_url = f"https://graph.facebook.com/v21.0/{ig_user_id}/media_publish"
pub_res = requests.post(publish_url, data={"creation_id": creation_id, "access_token": page_access_token}).json()
print(f"🎉 Reel published live! Post ID: {pub_res.get('id')}")
return pub_res.get("id")
DEVELOPER TOOLKIT
Download the Headless Video Automation Pipeline Code
The Python/FFmpeg template with caption overlays and custom transitions to programmatically generate social media reels & shorts.