npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rediska1114/tiktok-api

v1.0.7

Published

TikTok API library for fetching user profiles, posts, and challenges

Downloads

109

Readme

@rediska1114/tiktok-api

TikTok API library for fetching user profiles, posts, and challenges using official TikTok API endpoints with URL signing (X-Bogus and X-Gnarly).

Installation

npm install @rediska1114/tiktok-api

Peer Dependencies

This library requires the following peer dependencies:

npm install axios async-retry https-proxy-agent

Usage

ES Modules

import { getUser, getUserPosts, getChallenge } from '@rediska1114/tiktok-api';

// Get user profile
const userResult = await getUser('username', undefined, 'US');
if (userResult.error) {
  console.error('Error:', userResult.error);
} else {
  console.log('User:', userResult.data.userInfo.user);
  console.log('Stats:', userResult.data.userInfo.stats);
  console.log('msToken:', userResult.msToken);
}

// Get user posts (with msToken from getUser response)
const postsResult = await getUserPosts(
  userResult.data.userInfo.user.secUid,
  undefined,
  10,
  'US',
  userResult.msToken
);
if (postsResult.error) {
  console.error('Error:', postsResult.error);
} else {
  console.log('Posts:', postsResult.data);
}

// Get challenge/hashtag info
const challengeResult = await getChallenge('fyp', undefined, 'US');
if (challengeResult.error) {
  console.error('Error:', challengeResult.error);
} else {
  console.log('Challenge:', challengeResult.data);
}

CommonJS

const { getUser, getUserPosts, getChallenge } = require('@rediska1114/tiktok-api');

// Get user profile
getUser('username').then(userResult => {
  if (userResult.error) {
    console.error('Error:', userResult.error);
  } else {
    console.log('User:', userResult.data.userInfo.user);
  }
});

API

getUser(username: string, proxy: string | undefined | null, region: string, msToken?: string)

Fetches user profile information from TikTok API.

Parameters:

  • username - TikTok username (with or without @)
  • proxy - HTTP proxy URL (can be undefined or null)
  • region - Region code (e.g., 'GB', 'US', 'FR')
  • msToken (optional) - TikTok msToken for request authentication

Returns: Promise<TiktokStalkUserResponse>

{
  error?: string;
  statusCode?: number;
  data: TiktokUserDetailResponse | null;
  msToken?: string;
}

getUserPosts(secUid: string, proxy: string | undefined | null, postLimit: number | undefined, region: string, msToken?: string)

Fetches user posts with automatic msToken rotation.

Parameters:

  • secUid - User's secure ID (obtained from getUser)
  • proxy - HTTP proxy URL (can be undefined or null)
  • postLimit - Maximum number of posts to fetch (can be undefined)
  • region - Region code (e.g., 'GB', 'US', 'FR')
  • msToken (optional) - TikTok msToken for request authentication (rotates automatically)

Returns: Promise<TiktokUserPostsResponse>

{
  error?: string;
  statusCode?: number;
  data: Posts[] | null;
  totalPosts: number;
}

getChallenge(hashtag: string, proxy: string | undefined | null, region: string, msToken?: string)

Fetches challenge/hashtag information from TikTok API.

Parameters:

  • hashtag - Hashtag/challenge name
  • proxy - HTTP proxy URL (can be undefined or null)
  • region - Region code (e.g., 'GB', 'US', 'FR')
  • msToken (optional) - TikTok msToken for request authentication

Returns: Promise<{ error?: string; statusCode?: number; data: TiktokChallengeResponse | null }>

Features

  • ✅ Official TikTok API endpoints
  • ✅ URL signing with X-Bogus (RC4) and X-Gnarly (ChaCha20)
  • ✅ Automatic msToken extraction and rotation
  • ✅ Retry logic with exponential backoff
  • ✅ Proxy support
  • ✅ Full TypeScript support
  • ✅ Dual module format (ESM + CommonJS)
  • ✅ Preserves directory structure for better tree-shaking

Types

All TypeScript types are exported from the main module:

import type {
  TiktokStalkUserResponse,
  TiktokUserDetailResponse,
  UserProfile,
  StatsUserProfile,
  StatsV2UserProfile,
  TiktokUserPostsResponse,
  Posts,
  TiktokChallengeResponse,
  TiktokError
} from '@rediska1114/tiktok-api';

Error Handling

The library uses error codes from TikTok API:

enum TiktokError {
  HASHTAG_NOT_EXIST = 10205,
  HASHTAG_BLACK_LIST = 10209,
  HASHTAG_SENSITIVITY_WORD = 10211,
  HASHTAG_UNSHELVE = 10212,
  USER_BAN = 10221,
  USER_PRIVATE = 10222,
  USER_NOT_EXIST = 10202,
  INVALID_ENTITY = 10201,
}

References

This library uses URL signing techniques based on research from:

License

ISC