Skip to content

RankingReels Pipeline

Pull a creator's top-performing reels across TikTok and Instagram, score by engagement, and produce a ranked CSV plus a JSON manifest for downstream rendering.

Steps

  1. Resolve the creator handle on both platforms.
  2. Pull profile videos (TikTok) and reels (Instagram) with pagination.
  3. Compute an engagement score per asset: (likes + comments + shares) / followers.
  4. Sort descending and keep the top 25.
  5. Write a CSV plus a JSON manifest containing video URLs and transcripts.

Node Script

js
import fs from 'node:fs';
import { stringify } from 'csv-stringify/sync';

const SC_KEY = process.env.SCRAPECREATORS_API_KEY;

async function sc(path, params) {
  const qs = new URLSearchParams(params).toString();
  const res = await fetch(`https://api.scrapecreators.com${path}?${qs}`, {
    headers: { 'x-api-key': SC_KEY },
  });
  if (!res.ok) throw new Error(`${path} -> ${res.status}`);
  return res.json();
}

async function rankCreator(tiktokHandle, instagramHandle) {
  const tiktokProfile = await sc('/v1/tiktok/profile', { handle: tiktokHandle });
  const tiktokVideos = await sc('/v3/tiktok/profile/videos', { handle: tiktokHandle });

  const igProfile = await sc('/v1/instagram/profile', { handle: instagramHandle });
  const igReels = await sc('/v1/instagram/user/reels', { handle: instagramHandle });

  const tiktokFollowers = tiktokProfile.stats?.followerCount || 1;
  const igFollowers = igProfile?.user?.edge_followed_by?.count || 1;

  const tiktokRanked = (tiktokVideos.videos || []).map((v) => ({
    platform: 'tiktok',
    url: `https://www.tiktok.com/@${tiktokHandle}/video/${v.id}`,
    score: ((v.stats?.diggCount || 0) + (v.stats?.commentCount || 0) + (v.stats?.shareCount || 0)) / tiktokFollowers,
    raw: v,
  }));

  const igRanked = (igReels.reels || []).map((r) => ({
    platform: 'instagram',
    url: `https://www.instagram.com/reel/${r.shortcode}`,
    score: ((r.like_count || 0) + (r.comment_count || 0)) / igFollowers,
    raw: r,
  }));

  return [...tiktokRanked, ...igRanked].sort((a, b) => b.score - a.score).slice(0, 25);
}

const top = await rankCreator('stoolpresidente', 'stoolpresidente');
fs.writeFileSync('top-reels.json', JSON.stringify(top, null, 2));
fs.writeFileSync(
  'top-reels.csv',
  stringify(top.map(({ raw, ...rest }) => rest), { header: true })
);
console.log(`Wrote ${top.length} ranked reels.`);

Notes

  • This costs roughly 4 credits per creator (2 profile, 2 list endpoints).
  • Add GET /v1/tiktok/video/transcript per top reel if you want to feed text into a ranking model.
  • Use country and time_period filters on GET /v1/tiktok/videos/popular to scope the trending pool.
  • GET /v1/tiktok/profile
  • GET /v3/tiktok/profile/videos
  • GET /v1/instagram/profile
  • GET /v1/instagram/user/reels
  • GET /v1/youtube/channel-videos