@tikfly/client
v1.0.0
Published
Unofficial TikTok API at scale without the usual limitations
Readme
Tikfly API
Unofficial TikTok API Wrapped in Node.js & TypeScript
Available on NPM
Installation
npm install @tikfly/client
# or
yarn add @tikfly/client
# or
pnpm add @tikfly/clientUsage
Get TikTok User Info
import { Tikfly } from "@tikfly/client";
const API_KEY = "YOUR_API_KEY"; // How to get your api key -> https://docs.tikfly.io/getting-started/quickstart
const USERNAME = "taylorswift"; // Change to the user you want to get data from
async function getTikTokUserInfo() {
const tikfly = new Tikfly(API_KEY);
const res = await tikfly.user.getUserInfo({
unique_id: USERNAME,
});
console.log(res.userInfo);
}
getTikTokUserInfo();Get Tiktok User Videos
import { Tikfly } from "@tikfly/client";
const API_KEY = "YOUR_API_KEY"; // How to get your api key -> https://docs.tikfly.io/getting-started/quickstart
const USERNAME = "taylorswift"; // Change to the user you want to get data from
const NUM = 50; // Max number of videos to fetch
async function getTikTokUserVideos() {
const tikfly = new Tikfly(API_KEY);
console.log(`Fetching ${NUM} videos of user: ${USERNAME}`);
const resUserInfo = await tikfly.user.getUserInfo({
unique_id: USERNAME,
});
const userSecUid = resUserInfo.userInfo.user.secUid;
console.log("User secUid:", userSecUid);
let results: any[] = [];
let cursor = 0;
const count = 15;
let hasMore = true;
while (hasMore && results.length < NUM) {
console.log(`Current cursor: ${cursor}`);
const res = await tikfly.user.getUserPosts({
secUid: userSecUid,
count,
cursor,
});
const itemList = res.itemList || [];
if (!itemList.length) break;
results.push(...itemList);
hasMore = res.hasMore;
cursor = res.cursor;
}
results = results.slice(0, NUM);
for (const video of results) {
console.log(`- ${video.id}: ${video.desc}`);
}
}
getTikTokUserVideos();Download Tiktok Videos (Without Watermark)
import { Tikfly } from "@tikfly/client";
import fs from "fs";
import axios from "axios";
const API_KEY = "YOUR_API_KEY"; // How to get your api key -> https://docs.tikfly.io/getting-started/quickstart
async function downloadVideo(url: string, path: string) {
const res = await axios({
url,
method: "GET",
responseType: "stream",
});
const writer = fs.createWriteStream(path);
res.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on("finish", resolve);
writer.on("error", reject);
});
}
async function run() {
const tikfly = new Tikfly(API_KEY);
const videoUrl = "https://www.tiktok.com/@taylorswift/video/7558098574555254046";
const res = await tikfly.video.download(videoUrl);
const downloadUrl = res.play;
console.log("Download URL:", downloadUrl);
if (downloadUrl) {
const videoId = videoUrl.split("/").pop();
await downloadVideo(downloadUrl, `${videoId}.mp4`);
}
}
run();Tutorials
- Tikfly API Documentation
- How to get Rapid API Key
- Working with Cursor in TikTok API for Pagination
- What is Tiktok User secUid?
- How TikTok Classifies a Video?
Contributing
Contributions are welcome! If you find this project helpful, please consider starring the repository on GitHub ⭐️
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Disclaimer
This project is an independent, open-source tool and is not affiliated, endorsed, or sponsored by TikTok.
