SocialCrawl

Frameworks

SocialCrawl with Nuxt

Read a profile, search many platforms and page through posts from Nuxt server routes

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

Prerequisites

  • Node.js 22 or later.
  • Nuxt 4. The code is the same on Nuxt 3.
  • A SocialCrawl API key. Keys start with sc_.

Checking your account…

Set up

There is no package to install. Put your key in .env at the project root.

Terminal
echo "SOCIALCRAWL_API_KEY=sc_your_key_here" >> .env

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. Nitro imports everything in server/utils on its own, so the routes call socialcrawl with no import.

server/utils/socialcrawl.ts
import type { H3Event } from "h3";

const API = "https://www.socialcrawl.dev";

// Send one request with your key and answer with the API's JSON and status.
// The JSON carries success, and error.type and error.doc_url when it is false.
export async function socialcrawl(event: H3Event, path: string, params: Record<string, string>) {
  const res = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
    headers: { "x-api-key": process.env.SOCIALCRAWL_API_KEY ?? "" },
  });
  setResponseStatus(event, res.status);
  return res.json();
}
server/api/profile.get.ts
export default defineEventHandler((event) => {
  const { handle = "charlidamelio" } = getQuery(event);
  return socialcrawl(event, "/v1/tiktok/profile", { handle: String(handle) });
});

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.

server/api/search.get.ts
// dry_run=1 prices the search and runs nothing.
export default defineEventHandler((event) => {
  const { query = "oat milk" } = getQuery(event);
  return socialcrawl(event, "/v1/search/everywhere", {
    query: String(query),
    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.

server/api/posts.get.ts
// Send the last answer's pagination.next_cursor back as ?cursor=.
export default defineEventHandler((event) => {
  const { handle = "charlidamelio", cursor } = getQuery(event);
  const params: Record<string, string> = { handle: String(handle) };
  if (cursor) params.cursor = String(cursor);
  return socialcrawl(event, "/v1/tiktok/profile/videos", params);
});

A page of posts costs 1 credit.

Test it

Start the app with npm run dev, 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

Ready to build?

Start getting social data for free and scale as your project grows. No credit card needed.