← 返回
开发者工具 Key 中文

Instagram Collector Adarsh

Collects Instagram profile metrics for a handle using Apify, returning followers, posts, engagement rate, posting frequency, avg likes/comments, and top hash...
使用 Apify 收集 Instagram 账号的关注者、帖子数、参与率、发布频率、平均点赞/评论数以及热门话题标签等指标。
adarshvmore
开发者工具 clawhub v1.0.1 1 版本 100000 Key: 需要
★ 0
Stars
📥 558
下载
💾 8
安装
1
版本
#latest

概述

Instagram Collector Skill

Purpose

Collects Instagram profile data for a given handle using the Apify Instagram Profile Scraper. Extracts follower count, engagement metrics, posting frequency, and top hashtags. This collector feeds into the Marketing Audit Pipeline to populate the Instagram Performance section of the final report.

Input Schema

// Function signature
collectInstagram(handle: string): Promise<InstagramData>

// The handle parameter is the Instagram username without the @ symbol.
// Example: "gymshark" (not "@gymshark")

Output Schema

interface InstagramData {
 followers: number;
 posts: number;
 engagementRate: number; // Calculated: (avgLikes + avgComments) / followers * 100
 postingFrequency: string; // e.g. "1.2 posts/day", "3 posts/week", "unknown"
 avgLikes: number;
 avgComments: number;
 topHashtags: string[]; // Up to 10 most-used hashtags from recent posts
 error?: string; // Present only when collector fails
}

API Dependencies

  • API Name: Apify Instagram Profile Scraper
  • Actor ID: apify~instagram-profile-scraper
  • Endpoint: https://api.apify.com/v2/acts/apify~instagram-profile-scraper/runs
  • Auth: APIFY_API_TOKEN environment variable
  • Cost estimate: ~$0.005 per run on Apify free/paid tier
  • Rate limits: Depends on Apify plan; free tier allows limited concurrent runs

Implementation Pattern

Data Flow

  1. Receive handle string from the pipeline
  2. Call apifyService.scrapeInstagramProfile(handle) which starts an Apify actor run
  3. Apify runs asynchronously -- the service polls for completion (timeout: 60s)
  4. Fetch the actor's dataset results once complete
  5. Map the raw Apify response to the InstagramData interface

Engagement Rate Calculation

engagementRate = ((avgLikes + avgComments) / followers) * 100;
  • If followers is 0, set engagementRate to 0 to avoid division by zero
  • Engagement rate is expressed as a percentage (e.g., 3.5 means 3.5%)

Posting Frequency Calculation

  • Analyze timestamps from the last 30 posts returned by Apify
  • Calculate the time span between the oldest and newest post
  • Divide the number of posts by the number of days in that span
  • Format as a human-readable string:
  • >= 1 post/day: "X.X posts/day"
  • < 1 post/day but >= 1/week: "X posts/week"
  • < 1 post/week: "X posts/month"
  • If no timestamp data available: "unknown"

Top Hashtags Extraction

  • Iterate through captions of recent posts
  • Extract all #hashtag tokens using regex: /#(\w+)/g
  • Count frequency of each hashtag
  • Return the top 10 most frequently used

Apify Response Mapping

Key fields from Apify's raw output:

  • followersCount -> followers
  • postsCount -> posts
  • latestPosts[].likesCount -> used for avgLikes
  • latestPosts[].commentsCount -> used for avgComments
  • latestPosts[].caption -> used for hashtag extraction
  • latestPosts[].timestamp -> used for posting frequency

Error Handling

  • Entire function wrapped in try/catch
  • On failure, return EMPTY_INSTAGRAM_DATA with error field set:

```typescript

return { ...EMPTY_INSTAGRAM_DATA, error: 'Instagram data unavailable: ' };

```

  • Never throw -- always return a valid InstagramData object
  • Log errors with Winston logger including handle and error details:

```typescript

logger.error('Instagram collector failed', { handle, err });

```

  • Common failure scenarios:
  • Apify token invalid or expired
  • Actor run timeout (profile too large or Apify overloaded)
  • Profile is private or does not exist
  • Rate limit exceeded on Apify

Example Usage

import { collectInstagram } from '../collectors/instagramCollector';

// Successful collection
const data = await collectInstagram('gymshark');
// Returns:
// {
// followers: 6800000,
// posts: 4520,
// engagementRate: 1.85,
// postingFrequency: "1.3 posts/day",
// avgLikes: 120000,
// avgComments: 5800,
// topHashtags: ["gymshark", "fitness", "gym", "workout", "fitnessmotivation", ...],
// }

// Failed collection (graceful degradation)
const failedData = await collectInstagram('nonexistent_handle_12345');
// Returns:
// {
// followers: 0,
// posts: 0,
// engagementRate: 0,
// postingFrequency: "unknown",
// avgLikes: 0,
// avgComments: 0,
// topHashtags: [],
// error: "Instagram data unavailable: Profile not found"
// }

Notes

  • The collector depends on apifyService.ts for the actual API communication. The collector handles only data mapping and calculations.
  • Apify actor runs are asynchronous. The service layer handles polling. If the run does not complete within 60 seconds, it should be treated as a timeout error.
  • This collector is independently testable. In tests, mock apifyService.scrapeInstagramProfile to return fixture data.
  • Instagram data can be stale -- Apify scrapes public data which may be cached. This is acceptable for audit purposes.
  • The EMPTY_INSTAGRAM_DATA constant is defined in src/types/audit.types.ts and should be imported for fallback returns.
  • This collector must never block the pipeline. Even a complete failure returns valid typed data with an error flag, allowing other collectors to proceed.

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-03-30 13:19 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 68 📥 180,150
security-compliance

Marketing Orchestrator Adarsh

adarshvmore
统筹营销审计,收集 Instagram、Meta Ads、SEO、竞争对手及网站数据,生成综合报告。
★ 0 📥 578
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 668 📥 324,133