This walks through subscribing to Instagram mentions and comments and receiving them in this app.
- App running with a public HTTPS URL (e.g. Cloudflare Tunnel) to
http://localhost:8000 .envfilled with valid Meta credentials- Instagram professional account linked to your app / Page
-
In Meta for Developers open your app → Webhooks.
-
Select the Instagram webhook configuration (Instagram Graph / Instagram object).
-
Set Callback URL to:
https://YOUR-TUNNEL-HOST/webhook -
Set Verify token to the exact value of
META_WEBHOOK_VERIFY_TOKENin.env. -
Save. Meta sends
GET /webhook?hub.mode=subscribe&hub.verify_token=...&hub.challenge=....
Your server must return HTTP 200 and a plain-text body equal to hub.challenge.
Manual check:
curl -sS "https://YOUR-TUNNEL/webhook?hub.mode=subscribe&hub.verify_token=YOUR_TOKEN&hub.challenge=test123"
# expect: test123In the same Webhooks → Instagram screen, subscribe to:
- mentions
- comments
Save. (Production may require Live mode and Advanced Access for comments — see Instagram webhooks.)
When someone comments on your media or you get a mention (per Meta rules), Meta POSTs JSON to /webhook.
This app:
- Optionally verifies
X-Hub-Signature-256ifINSTAGRAM_APP_SECRETis set. - Stores each change in
webhook_events. - For
comments, also inserts intotracked_commentsif not already present.
Inspect deliveries:
curl -sS "http://localhost:8000/webhook/events?limit=20"Webhook payloads include identifiers (e.g. media_id). Use:
GET /instagram/user/{INSTAGRAM_USER_ID}/mentioned_media/{media_id}(Requires the right permissions; see the Instagram Graph docs.)
| Symptom | Check |
|---|---|
| Verify fails | Tunnel up, token matches, URL is https, path /webhook |
| POST 403 | Signature: set INSTAGRAM_APP_SECRET correctly or leave empty to skip |
| No events | App Live mode, subscribed fields, test user in Development mode |