The TikHub API TypeScript SDK provides an easy-to-use TypeScript/JavaScript client for interacting with the TikHub API, supporting platforms like TikTok, Douyin, Instagram, and more.
@tikhub/[email protected]
This generator creates TypeScript/JavaScript client that utilizes axios. The generated Node module can be used in the following environments:
Environment
- Node.js
- Webpack
- Browserify
Language level
- ES5 - you must have a Promises/A+ library installed
- ES6
Module system
- CommonJS
- ES6 module system
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via package.json
. (Reference)
To build and compile the typescript sources to javascript use:
npm i @tikhubio/tikhub-api-ts-sdk
- 🚀 Fully Typed TypeScript SDK – Provides complete type definitions.
- 🔑 API Key Authentication – Secure access to TikHub API.
- ⚡ Built with Axios – Supports automatic request handling and retries.
- 🎯 ES6+ Compatible – Works in Node.js, Webpack, Browserify.
Install via npm:
npm i @tikhubio/tikhub-api-ts-sdk --save
Before making API requests, configure the API Client with your API Key and Base URL.
import { Configuration } from "@tikhubio/tikhub-api-ts-sdk";
// Create an API configuration instance
const config = new Configuration({
basePath: "https://api.tikhub.io", // ✅ Set API base URL
accessToken: "YOUR_API_KEY", // ✅ Set API Key for authentication
});
console.log("TikHub API Client Config initialized!");
📌 Replace YOUR_API_KEY
with your actual API key.
Fetch videos associated with a given hashtag.
import { TikTokAppV3APIApi } from '@tikhubio/tikhub-api-ts-sdk';
const api = new TikTokAppV3APIApi(config);
async function fetchUserProfile() {
try {
const response = await api.handlerUserProfileApiV1TiktokAppV3HandlerUserProfileGet_52('', 'MS4wLjABAAAAv7iSuuXDJGDvJkmH_vz1qkDZYo1apxgzaxdBSeIuPiM', '', '');
console.log('User Profile Info:', response.data);
} catch (error) {
console.error('Error fetching User profile info:', error);
};
}
fetchUserProfile();
🔹 Parameters:
userId
: User ID (string) OptionalsecUserId
: Secondary User ID (string) OptionaluniqueId
: Unique ID (string) Optional
Retrieve TikTok's recommended videos based on cookies.
import { TikTokAppV3APIApi, TikTokAppV3HomeFeed } from '@tikhubio/tikhub-api-ts-sdk';
const api = new TikTokAppV3APIApi(config);
async function fetchHomeFeed() {
try {
const TikTokAppV3HomeFeed = {
cookie: 'your_tiktok_cookie_here',
};
const response = await api.fetchHomeFeedApiV1TiktokAppV3FetchHomeFeedPost(TikTokAppV3HomeFeed);
console.log('Home Feed:', response.data);
} catch (error) {
console.error('Error fetching home feed:', error);
}
}
fetchHomeFeed();
🔹 Parameters:
cookie
: TikTok user cookie (optional, used for personalization)
Retrieve TikTok user profile information.
import { TikTokAppV3APIApi } from '@tikhubio/tikhub-api-ts-sdk';
const api = new TikTokAppV3APIApi(config);
async function fetchUserProfile(userId: string) {
try {
const response = await api.fetchUserProfileApiV1TiktokAppV3FetchUserProfileGet(userId);
console.log('User Profile:', response.data);
} catch (error) {
console.error('Error fetching user profile:', error);
}
}
fetchUserProfile('123456789');
🔹 Parameters:
userId
: TikTok user ID (string)