SocialCrawl

Frameworks

SocialCrawl with Hono

Build a Hono app that reads a profile, searches many platforms and pages through posts, on any runtime

The app serves three routes under /api, and each answers with the API's JSON unchanged.

Prerequisites

  • Node.js 22.18 or later, which runs TypeScript as it is.
  • Hono 4.
  • A SocialCrawl API key. Keys start with sc_.

계정을 확인하는 중입니다.

Set up

Install Hono and its Node server, then set your key.

Terminal
npm install hono @hono/node-server
export SOCIALCRAWL_API_KEY=sc_your_key_here

Keep the key on the server, out of your code and out of the browser.

Get a profile

The helper sends your key in the x-api-key header and answers with the API's JSON and status.

src/index.ts
import { Hono } from "hono";
import { env } from "hono/adapter";
import type { Context } from "hono";

const API = "https://www.socialcrawl.dev";
const app = new Hono();

// Send one request with your key and answer with the API's JSON and status.
// env(c) reads the key the same way on Node, Bun, Deno and Workers.
async function socialcrawl(c: Context, path: string, params: Record<string, string>) {
  const { SOCIALCRAWL_API_KEY } = env<{ SOCIALCRAWL_API_KEY: string }>(c);
  const res = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
    headers: { "x-api-key": SOCIALCRAWL_API_KEY },
  });
  return Response.json(await res.json(), { status: res.status });
}

app.get("/api/profile", (c) =>
  socialcrawl(c, "/v1/tiktok/profile", { handle: c.req.query("handle") ?? "charlidamelio" }),
);

Every answer carries success. Branch on it, then on error.type, never on the message text.

Search across platforms

With dry_run=1 the search is free and runs nothing. data.estimate holds the credits and seconds the real search would take.

src/index.ts
// dry_run=1 prices the search and runs nothing.
app.get("/api/search", (c) =>
  socialcrawl(c, "/v1/search/everywhere", {
    query: c.req.query("query") ?? "oat milk",
    format: "compact",
    dry_run: "1",
  }),
);

Drop dry_run to run the search for 20 credits.

Get posts and the next page

Each answer holds one page of posts in data.items. Send pagination.next_cursor back as cursor, and stop when pagination.has_more is false.

src/index.ts
// Send the last answer's pagination.next_cursor back as ?cursor=.
app.get("/api/posts", (c) => {
  const params: Record<string, string> = { handle: c.req.query("handle") ?? "charlidamelio" };
  const cursor = c.req.query("cursor");
  if (cursor) params.cursor = cursor;
  return socialcrawl(c, "/v1/tiktok/profile/videos", params);
});

export default app;

A page of posts costs 1 credit.

Deploy anywhere

src/index.ts never touches the runtime, so only the entry point changes. Bun runs it as it is with bun run src/index.ts, Deno with Deno.serve(app.fetch), and Cloudflare Workers with main set to it in wrangler.jsonc. On Node, src/server.ts starts it:

src/server.ts
import { serve } from "@hono/node-server";

import app from "./index.ts";

serve({ fetch: app.fetch, port: Number(process.env.PORT ?? 3000) });

Test it

Start the app with node src/server.ts, then call the three routes. The answers hold data.author.followers, data.estimate and pagination.next_cursor.

Terminal
curl "http://localhost:3000/api/profile?handle=charlidamelio"
curl "http://localhost:3000/api/search?query=oat+milk"
curl "http://localhost:3000/api/posts?handle=charlidamelio&cursor="

Next steps

On this page

시작할 준비가 됐습니까?

무료로 소셜 데이터를 받기 시작하고, 프로젝트가 커지면 그대로 확장합니다. 카드 등록은 필요 없습니다.