100 free credits. No credit card required. Get a key

How to scrape TikTok top videos with PHP

TikTok’s own top-videos board for a market: videos created in the last 7 or 30 days, by views, engagement or completion.

The examples use PHP’s curl extension and json_decode(..., true), so the response is a plain associative array. No Composer packages needed.

GET /v1/tiktok/trending/videos1 credit per callRefunded on failure

Before you start

  1. Get an API keySign up for 100 free credits, no card. Keys start with gs_live_.
  2. Put it in the environmentEvery example reads it from GROUNDSOCIAL_API_KEY: export GROUNDSOCIAL_API_KEY=gs_live_…
  3. Set up PHPphp -m | grep curl # the curl extension ships with most PHP builds

Call TikTok top videos API from PHP

GET /v1/tiktok/trending/videos. Save this as main.php and run php main.php. It reads the items in entityInfos and prints itemInfo.title and itemAuthorMetrics.followers for each.

main.php
<?php

function groundsocial(string $path, array $params = []): array
{
    $url = 'https://api.groundsocial.dev' . $path . ($params ? '?' . http_build_query($params) : '');
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('GROUNDSOCIAL_API_KEY')],
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 60,
    ]);
    $raw = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    curl_close($ch);
    $data = json_decode($raw, true);
    if ($status !== 200) {
        $e = $data['error'];
        throw new RuntimeException($e['code'] . ': ' . ($e['hint'] ?? $e['message']));
    }
    return $data;
}

$data = groundsocial('/v1/tiktok/trending/videos', ['country' => 'US', 'period' => '7']);

foreach ($data['entityInfos'] as $item) {
    echo $item['itemInfo']['title'] ?? '', ' ', $item['itemAuthorMetrics']['followers'] ?? '', PHP_EOL;
}

The response

A real TikTok response to this call, recorded from the live source and shortened for display: arrays keep their first items and … marks every cut. The recorded page had 2 items in entityInfos. Live calls return current data in the same shape.

200 OK
{
  "entityInfos": [
    {
      "itemInfo": {
        "itemID": "7691731357294152974",
        "authorID": "7532541110103867406",
        "contentType": 1,
        "coverURL": "https://p16-common-sign.tiktokcdn-us.com/tos-useast5-p-0068-tx/oogoQFgR5EB6M0TqAyC2QhQefQE…",
        "coverURLList": [
          {
            "…": "2 fields"
          },
          {
            "…": "2 fields"
          }
        ],
        "createTime": "1790870796",
        "creatorID": "6992810747127628805",
        "title": "AD sparkling through the city, as part of #thediamondcollective @The Diamond Collective ",
        "videoURL": "https://v16m-default.tiktokcdn-us.com/bc115036eff2290f90ca4abccb5c97e0/6b067eb5/video/tos/…"
      },
      "itemAuthorInfo": {
        "avatarURI": "https://p16-common-sign.tiktokcdn-us.com/tos-useast5-avt-0068-tx/5a124cccf2dadf0c7e34d0f4a…",
        "bio": "NYC\nArtist--multicurious lover\n⭐️subscribe to my youtube⭐️\nsebin@dulcedo.com",
        "handlerName": "deathstatequilibrium",
        "nickName": "sebin🌟"
      },
      "itemMetrics": {
        "engagementRate": 0.0004565897757430412,
        "engagementRateLifeTime": 0.0007131562268624228,
        "organicVideoViews": "5017483",
        "organicVideoViewsLifeTime": "31217086",
        "sixSecondsVTR": 0.009636825498597203,
        "sixSecondsVTRLifeTime": 0.011701371964817882,
        "videoViews": "51878078",
        "videoViewsLifeTime": "234968151"
      },
      "itemAuthorMetrics": {
        "followers": "117256"
      }
    },
    {
      "itemInfo": {
        "itemID": "7678479724896587038",
        "authorID": "7070293872819044358",
        "contentType": 1,
        "coverURL": "https://p16-common-sign.tiktokcdn-us.com/tos-useast8-p-0068-tx2/ocK3E0iPwBkRoAA5XXAPvCEAiB…",
        "coverURLList": [
          {
            "…": "2 fields"
          },
          {
            "…": "2 fields"
          }
        ],
        "createTime": "1787785387",
        "creatorID": "6880574638150697990",
        "title": "Five years ago, I started my small business with no idea what it would grow into. From wor…",
        "videoURL": "https://v16m-default.tiktokcdn-us.com/37a23ad1f71c39e1dfd697f1ad694d53/6b067ec4/video/tos/…"
      },
      "itemAuthorInfo": {
        "avatarURI": "https://p16-common-sign.tiktokcdn-us.com/tos-useast8-avt-0068-tx2/7d6ee80f6e94a044a88786ee…",
        "bio": "your favorite hand-drawn crewnecks &amp; tees\n🧸🤍🎨\nentrepreneur &amp; nurse\nShop Below ◡̈",
        "handlerName": "megannco",
        "nickName": "Meg Ann Co."
      },
      "itemMetrics": {
        "engagementRate": 0.0013633322396169325,
        "engagementRateLifeTime": 0.0016093465367882222,
        "organicVideoViews": "5187904",
        "organicVideoViewsLifeTime": "19207771",
        "sixSecondsVTR": 0.030609222943414737,
        "sixSecondsVTRLifeTime": 0.03216759125618045,
        "videoViews": "42046244",
        "videoViewsLifeTime": "195686257"
      },
      "itemAuthorMetrics": {
        "followers": "271347"
      }
    }
  ],
  "periodEndTimestamp": "1795392000",
  "page": 1,
  "hasMore": false
}

Top-level fields

FieldTypeDescription
entityInfosobject[]–
periodEndTimestampstring–
pagenumber–
hasMoreboolean–

Parameters

NameInTypeDescription
countryquerystringMarket (default US).
periodquery"7" | "30"Days: 7 (default) or 30. One of 7, 30.
orderquery"views" | "engagement" | "completion"views (default), engagement or completion. One of views, engagement, completion.
pagequeryintegerPage, from 1.

Errors and retries

Every error is JSON with error.code (stable: branch on it), message, hint (what to do next), docs_url and retryable. A failed call is never charged. Retry only when retryable is true, after the Retry-After header.

Errors
try {
    $data = groundsocial('/v1/tiktok/trending/videos', ['country' => 'US', 'period' => '7']);
} catch (RuntimeException $e) {
    // "code: hint", e.g. "target_not_found: ..." (never charged).
    fwrite(STDERR, $e->getMessage() . PHP_EOL);
    exit(1);
}
StatusMeaning
200The video board.
400Invalid input. Nothing was charged.
401Missing or invalid API key.
402Not enough credits, a spend cap was reached, or payment is required.
403The target is private, or the account is suspended.
404The account, video, comment, hashtag or sound does not exist on TikTok, or was removed.
429Too many requests. Wait for Retry-After seconds.
503TikTok is temporarily unavailable. Retryable; nothing was charged.

Every error code and what to do about it.

Pricing

Cost
Per call1 credit per call
1,000 calls$1.00 on the starter pack, $0.40 at volume
No key (MPP or x402)$0.01 per call
Failed callRefunded, never charged

Every response has x-credits-charged and x-credits-remaining headers. Credits never expire. Packs and calculator.

From an AI agent (MCP)

The same call is the tiktok_videos_popular tool on the hosted MCP server, so Claude, Cursor or any MCP client can make it without code. Add the server once:

bash
claude mcp add --transport http groundsocial https://api.groundsocial.dev/mcp

Then ask for it in words (“TikTok’s top-videos board for a market and period”), or call the tool directly:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "tiktok_videos_popular",
    "arguments": {
      "country": "US",
      "period": "7"
    }
  }
}

MCP setup for Claude Desktop, Cursor, VS Code and ChatGPT.

Study what wins

Read the top videos weekly and note their formats and sounds.

Questions

Which markets?

TikTok publishes this board for the US, Japan, Vietnam, Thailand and Indonesia.

Keep going

Run it on your own data

One key for TikTok and 76 more platforms, over REST or MCP. Free credits on signup, no card.

TikTok is a trademark of ByteDance Ltd. We are not affiliated with or endorsed by TikTok or ByteDance.