Instagram API integration
Socialift is a Python SDK for the Instagram API. It supports both connection paths: Instagram Login (no Facebook Page needed) and login through a Facebook Page. OAuth and token refresh, Direct conversations, image, Reels and carousel publishing, comments, insights and webhook signature checks live in one SDK, with appsecret_proof, retries and Page tokens handled for you.
Updated:
What is the Instagram API and what is it for?
The Instagram API is Meta's interface that lets an app publish posts, moderate comments, answer Direct messages and read insights on behalf of an Instagram professional account (Business or Creator). Personal accounts are not supported. A linked Facebook Page is required only for the Facebook Login setup; the Instagram Login setup works without a Page.
In practice companies use the Instagram API for three jobs: publishing content automatically, moving customer conversations into a CRM or support desk, and collecting advertising and lead data.
There are two ways in. With Instagram Login the user signs in with Instagram, requests go to graph.instagram.com and no Facebook Page is needed. With Facebook Login you need a Meta app, the user's OAuth consent, their Pages, a Page token and the Instagram account ID linked to that Page. In the SDK the first path is Instagram(app_id, app_secret), the second is fb.pages() plus Instagram.via_facebook(...).
What is supported on the Instagram side
Everything below ships with the SDK — no deep Graph API knowledge required.
OAuth and tokens
Login URL, code exchange (exchange_code returns a 60-day token straight away) and refresh_token for Instagram Login tokens. On the Facebook path, Page tokens come from fb.pages() and access is revoked with fb.revoke().
Direct conversations
Conversation and message lists. Every participant comes with a full profile: name, follower count, whether they follow the business.
Posts and comments
Publish images, videos and Reels (publish) and 2–10-image carousels (publish_carousel), read media; reply to, hide and delete comments. Files are passed as a public HTTPS URL.
Insights and demographics
Account metrics (insights, up to a 30-day range), per-post metrics (media_insights) and follower demographics (demographics: age/gender, city, country). Meta withholds some metrics for accounts with fewer than 100 followers.
Lead Ads and ads
Lead forms from Instagram ads are read through the Facebook Page: fb.lead_forms, fb.leads, fb.lead. The leadgen webhook arrives at your endpoint; you fetch the lead, shape it with leads.normalize() and write it to your CRM. Ads.boost_post turns an Instagram post into an ad created PAUSED.
Webhooks
X-Hub-Signature-256 verification (verify_request), event splitting (parse_events) and a dedupe key for repeated deliveries (dedupe_key).
Your first request — from OAuth to the Instagram account
On the Facebook Login path, once the user signs in, their Pages and the Instagram accounts linked to them come back in a single call.
import asyncio
from socialift import Facebook
async def main(code: str):
# FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, SOCIALIFT_LICENSE_KEY
async with Facebook.from_env() as fb:
token = await fb.exchange_code(code, redirect_uri="https://your-domain/cb")
for page in await fb.pages(token.access_token):
print(page.name, "→ instagram:", page.instagram_username)
asyncio.run(main(code="...")) # ?code= from the OAuth callbackThree Graph API calls (code → token, token → Pages, Page → IG account) collapse into one interface here. The appsecret_proof signature is added for you.
On the Instagram Login path (no Page), the same flow uses Instagram.from_env() (INSTAGRAM_APP_ID, INSTAGRAM_APP_SECRET) and ig.exchange_code(...).
Reading Direct conversations
The Conversations API returns only a participant's ID and username. conversations() adds each contact's name, follower count and follow status from the User Profile API, fetched in parallel with at most 8 requests at a time.
import asyncio, os
from socialift import Instagram
async def main(page_token: str):
async with Instagram.via_facebook(app_secret=os.environ["FACEBOOK_APP_SECRET"]) as ig:
chats = await ig.conversations(page_token, page_id="1111", ig_user_id="2222")
for chat in chats["data"]:
c = chat["contact"]
if c:
print(c.get("name"), c.get("follower_count"), "follows us:", c.get("is_user_follow_business"))
asyncio.run(main("PAGE_TOKEN"))The is_user_follow_business field matters to sales teams: whether the person writing already follows you decides how you prioritise the reply.
How do you publish a story through the API?
A story differs from an ordinary post in exactly one way: the container carries media_type=STORIES and goes out through the same media_publish step. There is no caption — story captions are not shown. Meta's media rules: JPEG images up to 8 MB at a recommended 9:16 ratio; MOV or MP4 video, 3–60 seconds, up to 100 MB.
import asyncio, os
from socialift import Instagram
async def main(page_token: str):
async with Instagram.via_facebook(app_secret=os.environ["FACEBOOK_APP_SECRET"]) as ig:
story = await ig.publish_story(page_token, ig_user_id="2222",
image_url="https://cdn.your-domain/story.jpg")
print(story["media_id"])
live = await ig.stories(page_token, ig_user_id="2222", limit=25)
print(len(live), "stories are live right now")
asyncio.run(main("PAGE_TOKEN"))Permissions: instagram_business_content_publish on the Instagram Login path, instagram_content_publish plus pages_read_engagement on the Facebook Login path. For video the SDK waits for the container to finish; wait_timeout controls that wait.
Listing live stories (ig.stories) works only with a Facebook Login token: Meta marks that edge “Instagram API with Facebook Login only”, and on the Instagram Login path it does not exist at all. The list covers the last 24 hours only — archives and highlights are not exposed by the API.
The daily publishing limit applies to stories too, because they go through the same media_publish endpoint. Meta's own documentation contradicts itself here: the overview page states one number while the media_publish and content_publishing_limit pages state another. Don't guess — ask GET /{ig-user-id}/content_publishing_limit for the remaining quota.
Connecting Instagram in four steps
Prepare the Instagram account
Switch the account to Business or Creator. Linking a Facebook Page is required only on the Facebook Login path; Instagram Login (
Instagram(app_id, app_secret)) works without a Page.Create a Facebook app
Create an app in Meta for Developers and request only the permissions you use. For Instagram Login: instagram_business_basic plus, as needed, instagram_business_content_publish, instagram_business_manage_comments, instagram_business_manage_messages, instagram_business_manage_insights. For Facebook Login: pages_show_list, pages_read_engagement, instagram_basic plus, as needed, instagram_content_publish, instagram_manage_comments, instagram_manage_messages, instagram_manage_insights (leads_retrieval for leads). If your app serves accounts you don't own or manage, Advanced Access requires App Review and Business Verification.
Get a Socialift token
Sign in with Google or email, open “Tokenlar” (Tokens) in the dashboard, press “Yangi token” (New token) and copy the key that starts with slk_. The first month is free.
Wire up the SDK
pip install socialift, put the key in the SOCIALIFT_LICENSE_KEY environment variable and send your first call.
Instagram, Facebook, LinkedIn, TikTok and Telegram capabilities
Every platform runs in one SDK under one error model.
| Capability | TikTok | Telegram | |||
|---|---|---|---|---|---|
| Connection — OAuth; code or bot token on Telegram | yes | yes | yes | yes | yes |
| Profile data | yes | yes | yes | yes | yes |
| Posts — read and publish | yes | yes | yes | yes | yes |
| Delete a post | no | yes | yes | no | yes |
| Story — 24 hours | yes | yes | no | no | yes |
| Comments — reply and hide | yes | yes | no | yes | no |
| Delete a comment | yes | no | no | yes | no |
| Chat and messages | yes | no | no | no | yes |
| Insights | yes | no | no | yes | yes |
| Follower demographics | yes | no | no | no | no |
| Group and channel management | no | no | no | no | yes |
| Ads and targeting | yes | yes | no | no | no |
| Lead Ads — forms and leads | yes | yes | no | no | no |
| Webhooks — signature, events, dedupe | yes | yes | no | yes | yes |
yesnoScroll the table sideways
Notes and limits
Socialift does not support LinkedIn messaging or lead forms (LinkedIn's Lead Sync API requires a separate access application reviewed by LinkedIn). TikTok comments and daily metrics require a Business account; Telegram does not use OAuth — it connects with a code or bot token, and webhooks are for bots. The story row needs its caveats: on Telegram stories live on the account (MTProto) side and require either a Telegram Premium account or a channel with enough boosts — the Bot API cannot post stories; LinkedIn removed Stories entirely in 2021; and TikTok's Content Posting API covers video and photo posts only, with no story endpoint.
Before you ship to production
The mistakes that show up most often in Instagram integrations.
- Make sure server-side calls carry appsecret_proof: when “Require App Secret” is enabled in the app settings, Meta rejects calls without it (the SDK adds it whenever app_secret is set).
- Instagram calls (except messaging) fall under Business Use Case rate limits: watch the X-Business-Use-Case-Usage header and back off on RateLimitError.
- Compute the webhook signature over the raw body — re-serialising the JSON breaks the match.
- The same event can arrive more than once: Meta sends no event ID, so build a key from the payload (mid, leadgen_id, comment_id —
dedupe_keyin the SDK) and store it in a unique column. - Instagram Login tokens last 60 days: refresh them with
refresh_tokenonce they are over 24 hours old and before they expire. Page tokens derived from a long-lived user token have no expiry date but are invalidated in certain cases, such as revoked access. - When a user revokes access you get an AuthError — surface that state in your CRM UI.
Frequently asked questions
Can I connect a personal account to the Instagram API?
No. The Instagram API works only with professional accounts (Business or Creator). A linked Facebook Page is needed only for Facebook Login; with Instagram Login no Page is required.
Can I read and send Instagram Direct messages through the API?
Yes. Instagram Login needs instagram_business_basic and instagram_business_manage_messages; Facebook Login needs instagram_basic, instagram_manage_messages and pages_show_list. App Review is required only for accounts you don't own (Advanced Access). Only the user can start a conversation; Socialift returns conversations with the contact's profile.
Is the Instagram API free?
Meta does not charge separately for the Graph API but does limit request volume. Socialift works on a licence key: the first month is free, with every SDK feature unlocked — publishing, Direct, insights, ads and Lead Ads included. Then the token is renewed for 30-day periods from your balance, with the price shown in the dashboard and features depending on the token's plan — “Tekshirish va muhitlar” (Check and environments) in the dashboard shows the exact list. The dashboard Playground works regardless of plan.
Can I publish Instagram stories through the API?
Yes. The container is created with media_type=STORIES and published through media_publish; in the SDK that is a single call — ig.publish_story(token, ig_user_id=..., image_url=...). Captions are not accepted, because story caption text is not displayed. Meta's rules: JPEG images up to 8 MB, MOV or MP4 video of 3–60 seconds up to 100 MB, recommended ratio 9:16. A story disappears after 24 hours, and listing live stories (ig.stories) works only with a Facebook Login token.
What limits does the Instagram API have?
The main ones: a 24-hour messaging window, request rate limits, App Review (Advanced Access) for accounts you don't own, and professional (Business or Creator) accounts only. These limits come from Meta and no SDK can remove them.
Is Socialift an official Meta partner?
No. Socialift is an independent integration layer built on the public Graph API. We integrate with Instagram, but we do not hold official Meta partner status.
Sources
Related pages
Start your Instagram integration today
Sign in with Google or email, get a token in under a minute and send your first Graph API call.
Get a free token →