Skip to Content
tikdataapi.com

SDK

TypeScript 和 Python 的类型化客户端。

两个客户端都由 API 的 OpenAPI 文档生成,因此涵盖每个接口、参数和响应类型,并随 API 一起更新。它们都很轻量:每个方法对应一次 HTTP 调用,没有重试,也没有状态,返回与原始 API 相同的 credits_charged 和 balance_remaining 字段。

TypeScript

npm install tikdataapi
import { tikdataapi } from 'tikdataapi';

const api = tikdataapi({ apiKey: process.env.TIKDATAAPI_KEY! });

const { data: profile } = await api.getUser({ path: { user: 'tiktok' } });
console.log(profile?.data.followers, profile?.credits_charged);

const { data: page } = await api.getUserVideos({ path: { user: 'tiktok' }, query: { count: 16 } });
for (const v of page?.data ?? []) console.log(v.id, v.plays, v.description);

const { data: many } = await api.getUsers({ body: { usernames: ['tiktok', 'nba', 'espn'] } });
console.log(many?.items, many?.errors);

const { data: found } = await api.searchVideos({ query: { query: 'street food', count: 12 } });
for (const v of found?.data ?? []) console.log(v.id, v.author.username, v.plays);

const { data: accounts } = await api.searchUsers({ query: { query: 'cooking', count: 10 } });
for (const u of accounts?.data ?? []) console.log(u.username, u.followers, u.verified);

const { data: followers } = await api.getUserFollowers({ path: { user: 'tiktok' }, query: { count: 30 } });
for (const u of followers?.data ?? []) console.log(u.username, u.followers);

const { data: sound } = await api.getMusic({ path: { id: '6696419263248336898' } });
console.log(sound?.data.title, sound?.data.videos);

const { data: trending } = await api.getTrendingVideos({ query: { count: 16 } });
for (const v of trending?.data ?? []) console.log(v.id, v.author.username, v.plays);

const { data: sounds } = await api.searchMusic({ query: { query: 'lofi', count: 12 } });
for (const m of sounds?.data ?? []) console.log(m.id, m.title, m.author);

const { data: live } = await api.getUserLive({ path: { user: 'tiktok' } });
console.log(live?.data.live, live?.data.title, live?.data.viewers);

const { data: transcript } = await api.getVideoTranscript({ path: { id: '7708543740230536461' } });
console.log(transcript?.data.language, transcript?.data.text);

const { data: tags } = await api.searchHashtags({ query: { query: 'street food', count: 10 } });
for (const t of tags?.data ?? []) console.log(t.name, t.result_videos, t.result_plays);

每次调用都返回 { data, error, response }。当状态码不是 2xx 时,data 为 undefined,error 包含带有 code 的 API 错误。支持 Node 18+、Bun、Deno、浏览器和边缘运行时。

Python

pip install tikdataapi
import os

from tikdataapi import AuthenticatedClient
from tikdataapi.api.music import get_music
from tikdataapi.api.search import search_hashtags, search_music, search_users, search_videos
from tikdataapi.api.users import get_user, get_user_followers, get_user_live, get_user_videos, get_users
from tikdataapi.api.videos import get_trending_videos, get_video_transcript
from tikdataapi.models import (
    GetUsersBody,
    HashtagSummaryPage,
    LiveRoomResponse,
    MusicResponse,
    MusicSummaryPage,
    TranscriptResponse,
    UserBatch,
    UserPage,
    UserResponse,
    UserSummaryPage,
    VideoPage,
)

client = AuthenticatedClient(
    base_url="https://api.tikdataapi.com",
    token=os.environ["TIKDATAAPI_KEY"],
    prefix="",
    auth_header_name="x-api-key",
)

profile = get_user.sync("tiktok", client=client)
if isinstance(profile, UserResponse):
    print(profile.data.followers, profile.credits_charged)

page = get_user_videos.sync("tiktok", client=client, count=16)
if isinstance(page, VideoPage):
    for v in page.data:
        print(v.id, v.plays, v.description)

many = get_users.sync(client=client, body=GetUsersBody(usernames=["tiktok", "nba", "espn"]))
if isinstance(many, UserBatch):
    print(many.items, many.errors)

found = search_videos.sync(client=client, query="street food", count=12)
if isinstance(found, VideoPage):
    for v in found.data:
        print(v.id, v.author.username, v.plays)

accounts = search_users.sync(client=client, query="cooking", count=10)
if isinstance(accounts, UserSummaryPage):
    for u in accounts.data:
        print(u.username, u.followers, u.verified)

followers = get_user_followers.sync("tiktok", client=client, count=30)
if isinstance(followers, UserPage):
    for u in followers.data:
        print(u.username, u.followers)

sound = get_music.sync("6696419263248336898", client=client)
if isinstance(sound, MusicResponse):
    print(sound.data.title, sound.data.videos)

trending = get_trending_videos.sync(client=client, count=16)
if isinstance(trending, VideoPage):
    for v in trending.data:
        print(v.id, v.author.username, v.plays)

sounds = search_music.sync(client=client, query="lofi", count=12)
if isinstance(sounds, MusicSummaryPage):
    for m in sounds.data:
        print(m.id, m.title, m.author)

live = get_user_live.sync("tiktok", client=client)
if isinstance(live, LiveRoomResponse):
    print(live.data.live, live.data.title, live.data.viewers)

transcript = get_video_transcript.sync("7708543740230536461", client=client)
if isinstance(transcript, TranscriptResponse):
    print(transcript.data.language, transcript.data.text)

tags = search_hashtags.sync(client=client, query="street food", count=10)
if isinstance(tags, HashtagSummaryPage):
    for t in tags.data:
        print(t.name, t.result_videos, t.result_plays)

每个操作都有 sync、sync_detailed、asyncio 和 asyncio_detailed 四种形式。模块有 api.users、api.videos、api.hashtags、api.music、api.playlists、api.search、api.account 和 api.billing;get_related_videos、get_trending_videos 和 get_video_transcript 在 api.videos 中,get_user_live 在 api.users 中。sync 在 200 时返回响应的模型(UserResponse、VideoPage 等),在错误状态时返回 Error 模型,在 API 参考未列出的状态时返回 None。请像上面的示例那样,用 isinstance 检查类型。

方法

方法接口
getMe / get_meGET /v1/me
getUser / get_userGET /v1/users/{user}
getUsers / get_usersPOST /v1/users/batch
getUserVideos / get_user_videosGET /v1/users/{user}/videos
getUsersVideos / get_users_videosPOST /v1/users/videos/batch
getUserFollowers / get_user_followersGET /v1/users/{user}/followers
getUserFollowing / get_user_followingGET /v1/users/{user}/following
getUserReposts / get_user_repostsGET /v1/users/{user}/reposts
getUserPlaylists / get_user_playlistsGET /v1/users/{user}/playlists
getUserLive / get_user_liveGET /v1/users/{user}/live
getVideo / get_videoGET /v1/videos/{id}
getVideos / get_videosPOST /v1/videos/batch
getRelatedVideos / get_related_videosGET /v1/videos/{id}/related
getTrendingVideos / get_trending_videosGET /v1/trending/videos
getVideoTranscript / get_video_transcriptGET /v1/videos/{id}/transcript
getComments / get_commentsGET /v1/videos/{id}/comments
getCommentReplies / get_comment_repliesGET /v1/videos/{id}/comments/{comment_id}/replies
getHashtag / get_hashtagGET /v1/hashtags/{name}
getHashtagVideos / get_hashtag_videosGET /v1/hashtags/{name}/videos
getMusic / get_musicGET /v1/music/{id}
getMusicVideos / get_music_videosGET /v1/music/{id}/videos
getPlaylistVideos / get_playlist_videosGET /v1/playlists/{id}/videos
searchVideos / search_videosGET /v1/search/videos
searchUsers / search_usersGET /v1/search/users
searchMusic / search_musicGET /v1/search/music
searchLive / search_liveGET /v1/search/live
searchHashtags / search_hashtagsGET /v1/search/hashtags
listPacks、createCheckout / list_packs、create_checkout计费

视频搜索、账号搜索以及粉丝列表和关注列表于 2026-12-02 新推出。账号搜索的每个条目是简短的用户资料(UserSummary),其 followers 是约数。粉丝列表和关注列表中各条目的计数可能是约数;getUser / get_user 给出准确的计数。

声音、转发、播放列表、相关视频和热门视频于 2026-12-03 新推出。getMusic / get_music 返回一个 MusicDetail;其 videos(使用该声音的视频数)由 TikTok 取整。getUserPlaylists / get_user_playlists 返回 Playlist 条目;把某个条目的 id 传给 getPlaylistVideos / get_playlist_videos。getRelatedVideos / get_related_videos(一页,最多 16 个)和 getTrendingVideos / get_trending_videos(最多 50 个)不接受游标,也没有下一页。

声音搜索、直播和文字稿也于 2026-12-03 新推出。searchMusic / search_music 返回 MusicSummary 条目;把某个条目的 id 传给 getMusic / get_music。searchLive / search_live 返回 LiveRoom 条目,getUserLive / get_user_live 返回一个 LiveRoom;账号未在直播时为 live: false,不含直播间字段。LiveRoom 没有直播流地址。getVideoTranscript / get_video_transcript 返回一个 Transcript:segments(start 和 end 以秒计)和 text。lang 用于选择语言;没有字幕的视频返回 404。

话题标签搜索也于 2026-12-03 新推出。searchHashtags / search_hashtags 返回 HashtagSummary 条目,按在综合搜索约 24 个视频中的使用次数从多到少排列。其 result_videos 和 result_plays 只统计这些视频,而不是 TikTok 的总数:要获得总数,请把某个条目的 name 传给 getHashtag / get_hashtag。它不接受游标,也没有下一页。

user 是用户名(带不带 @ 都可以)或 sec_uid。把一页中的 next_cursor 作为 cursor 传回。

其他语言:OpenAPI 文档适用于任何代码生成器;无需编写代码的智能体可以使用 MCP 服务器。