Skip to main content

@idiomark/adapter-instagram

Instagram adapter for Idiomark extraction using the Instagram Graph API.

Features​

  • User Profile: Biography, website, follower/following counts, media count
  • Posts: Photos, videos, and carousel albums with captions and hashtags
  • Stories: Ephemeral 24-hour content with mentions and stickers
  • Comments: Discussion and engagement with replies support
  • Reels: Short-form video content filtering
  • Hashtags: Extract and analyze hashtag usage

Authentication​

Uses OAuth 2.0 with access token from Instagram Graph API.

import { InstagramAdapter } from '@idiomark/adapter-instagram'

const adapter = new InstagramAdapter({
accessToken: 'your_access_token',
userId: 'optional_user_id'
})

await adapter.authenticate()

Rate Limits​

Usage​

import { InstagramAdapter } from '@idiomark/adapter-instagram'

// Initialize adapter
const adapter = new InstagramAdapter({
accessToken: process.env.INSTAGRAM_ACCESS_TOKEN
})

// Authenticate
await adapter.authenticate()

// Fetch data for personality analysis
const content = await adapter.fetchData({
limit: 100,
includeReplies: true,
includeStories: true,
includeReels: true,
includeComments: true
})

// Or use specific methods
const posts = await adapter.fetchPosts({ limit: 50 })
const stories = await adapter.fetchStories({ limit: 25 })
const comments = await adapter.fetchComments({ limit: 100 })
const reels = await adapter.fetchReels({ limit: 25 })

// Extract raw text for personality analysis
const result = await adapter.extractRawText({ limit: 100 })
console.log(result.rawContent)
console.log(result.metadata)

// Health check
const health = await adapter.healthCheck()

// Get metrics
const metrics = adapter.getMetrics()
console.log(`Requests: ${metrics.requests}`)
console.log(`Calls remaining: ${metrics.callsRemaining}`)
console.log(`Reset time: ${new Date(metrics.resetTime)}`)

Data Types​

TypeDescription
profileUser profile information
postPosts (photos, videos, carousel albums)
storyEphemeral stories
commentComments and replies
reelShort-form video content

API Reference​

authenticate(): Promise<boolean>​

Validate access token and fetch user profile.

fetchData(options: FetchOptions): Promise<RawContent[]>​

Fetch all content types for personality analysis.

Options:

  • limit: Maximum number of items to fetch (default: 50)
  • startDate: Filter content after this date
  • endDate: Filter content before this date
  • includeReplies: Include comment replies (default: true)
  • includeStories: Include stories (default: true)
  • includeReels: Include reels (default: true)
  • includeComments: Include comments (default: true)

fetchPosts(options): Promise<InstagramMedia[]>​

Fetch user's media posts including photos, videos, and carousel albums.

fetchStories(options): Promise<InstagramStory[]>​

Fetch user's ephemeral stories (expires after 24 hours).

fetchComments(options): Promise<InstagramComment[]>​

Fetch comments on user's media with nested replies.

fetchReels(options): Promise<InstagramMedia[]>​

Fetch reels (short-form video content).

normalize(raw: RawContent): NormalizedContent​

Convert raw Instagram content to Idiomark normalized format.

healthCheck(): Promise<{ healthy: boolean; latency?: number; error?: string }>​

Check adapter health and API connectivity.

getMetrics(): Metrics​

Get current rate limit metrics and request statistics.

reset(): Promise<void>​

Reset adapter state and rate limit tracking.

dispose(): Promise<void>​

Clear sensitive data and reset state.

Content Structure​

Each content item includes:

  • id: Unique identifier
  • type: Content type (profile, post, comment)
  • text: Caption, comment text, or profile info
  • created_at: ISO timestamp
  • author: User information
  • metrics: Likes, comments, shares
  • metadata: Platform-specific data (media type, hashtags, etc.)

Error Handling​

The adapter handles:

  • Rate limit errors (429) with automatic retry
  • Authentication errors (401) with clear messages
  • Network errors with logging
  • Invalid data with graceful degradation

License​

MIT