| Note ❗ Personal Instagram accounts cannot use the Instagram Graph API for publishing content.
🧭 How to switch to a Creator Account- Open the Instagram App on your phone.
- Go to your Profile (bottom right icon).
- Tap the three lines (☰) in the top right corner.
- Tap Settings and activity.
- Scroll to Account type and tools.
- Tap Switch to professional account.
- Select Creator when prompted.
- Choose your category (e.g., Artist, Blogger, Public Figure).
- Review your contact info (you can keep it private).
- Connect to a Facebook Page (optional, but required for API use).
If you become a creator, here's a basic example of how to post content (image or video) to Instagram using the Instagram Graph API. This requires you to have: - A Facebook Developer Account.
- An Instagram Business or Creator Account.
- A Facebook Page connected to the Instagram Account.
- A Facebook App with the required permissions.
- An Access Token with
instagram_content_publish scope.
Step 1: Get an Access TokenYou need a long-lived access token from the Facebook Graph API. Generate it via the Facebook Graph Explorer with the instagram_basic, instagram_content_publish, and pages_read_engagement permissions.
Step 2: Get the Instagram Business Account IDRun this Graph API request: GET https://graph.facebook.com/v19.0/me/accounts?access_token=YOUR_ACCESS_TOKEN
This returns a list of pages. Get the Page ID associated with your Instagram account. Next, fetch the Instagram Business Account ID: GET https://graph.facebook.com/v19.0/PAGE_ID?fields=instagram_business_account&access_token=YOUR_ACCESS_TOKEN
Step 3: Upload an Image to InstagramUse the Instagram Business Account ID to create a post. Python Exampleimport requests
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
INSTAGRAM_ACCOUNT_ID = "YOUR_INSTAGRAM_BUSINESS_ACCOUNT_ID"
IMAGE_URL = "https://your-image-url.com/image.jpg"
CAPTION = "Hello from Instagram API!"
# Step 1: Upload Image
url = f"https://graph.facebook.com/v19.0/{INSTAGRAM_ACCOUNT_ID}/media"
payload = {
"image_url": IMAGE_URL,
"caption": CAPTION,
"access_token": ACCESS_TOKEN
}
response = requests.post(url, data=payload)
result = response.json()
if "id" in result:
creation_id = result["id"]
# Step 2: Publish Image
publish_url = f"https://graph.facebook.com/v19.0/{INSTAGRAM_ACCOUNT_ID}/media_publish"
publish_payload = {
"creation_id": creation_id,
"access_token": ACCESS_TOKEN
}
publish_response = requests.post(publish_url, data=publish_payload)
print(publish_response.json())
else:
print("Error:", result)
Step 4: Upload a Video to InstagramFor video, you need to use video_url instead of image_url. VIDEO_URL = "https://your-video-url.com/video.mp4"
# Step 1: Upload Video
video_payload = {
"video_url": VIDEO_URL,
"caption": "My video post",
"access_token": ACCESS_TOKEN
}
video_response = requests.post(url, data=video_payload)
video_result = video_response.json()
if "id" in video_result:
video_creation_id = video_result["id"]
# Step 2: Publish Video
video_publish_payload = {
"creation_id": video_creation_id,
"access_token": ACCESS_TOKEN
}
video_publish_response = requests.post(publish_url, data=video_publish_payload)
print(video_publish_response.json())
else:
print("Error:", video_result)
Step 5: Verify PostCheck if the post is published by running: GET https://graph.facebook.com/v19.0/{MEDIA_ID}?fields=permalink&access_token=YOUR_ACCESS_TOKEN
It returns a permalink to the Instagram post. |