Guides
Use and adapt Instagram-Meta-Business-API-Handler
Use and adapt Instagram-Meta-Business-API-Handler: A comprehensive TypeScript wrapper for Instagram Graph API. Manage posts, stories, comments, DMs, analytics and more with full type safety.
Use the documented interfaces and source layout for Instagram-Meta-Business-API-Handler. The sections below retain the README’s examples and configuration details.
Authentication
Exchange Code for Token
// After user authorizes your app, exchange code for token
const authResponse = await InstagramHandler.exchangeCodeForToken(
'YOUR_CLIENT_ID',
'YOUR_CLIENT_SECRET',
'YOUR_REDIRECT_URI',
'AUTHORIZATION_CODE'
);
console.log('Access Token:', authResponse.access_token);Get Long-Lived Token (60 days)
const longToken = await InstagramHandler.getLongLivedToken(
'YOUR_CLIENT_SECRET',
'SHORT_LIVED_TOKEN'
);
console.log('Long-lived token:', longToken.access_token);
console.log('Expires in:', longToken.expires_in, 'seconds');Refresh Access Token
const refreshed = await instagram.refreshAccessToken();
console.log('New token:', refreshed.access_token);Error Handling
try {
const mediaId = await instagram.postImage(url, caption);
console.log('Posted successfully:', mediaId);
} catch (error) {
console.error('Failed to post:', error.message);
// Handle error appropriately
}Troubleshooting
Token expired?
// Refresh your token
const newToken = await instagram.refreshAccessToken();Video not publishing?
- Videos take time to process (2-10 seconds)
- The handler automatically waits, but ensure video meets requirements
Comments not appearing?
- Check if comments are enabled on the post
- Verify you have
instagram_manage_commentspermission
DMs not working?
- Ensure you have
instagram_manage_messagespermission - User must have interacted with your account first
Insights not available?
- Insights require Instagram Business or Creator account
- Wait 24 hours for insights on new posts
Source and help
Source captured: 2026-10-11
