tiktok-api-unofficial
v0.1.0
Published
Unofficial TikTok API library: scrape video/user metadata and optionally download media (no API key required)
Maintainers
Readme
tiktok-api-unofficial (TypeScript)
Unofficial TikTok API library (TypeScript/Node): scrape video and user profile metadata, and optionally download videos, slides, and audio. No official API key required.
Install
From npm:
npm install tiktok-api-unofficialFrom GitHub:
git clone https://github.com/8dazo/tiktok_scrapper.git
cd tiktok_scrapper/tiktok-api-ts
npm install
npm run buildRequirements: Node.js 18+ (for native fetch). If you see Could not locate the bindings file for better-sqlite3, run:
npm rebuild better-sqlite3Usage
import { TTContentScraper } from "tiktok-api-unofficial";
const scraper = new TTContentScraper({
waitTime: 0.35,
outputDir: "data/",
progressDbPath: "progress_tracking/scraping_progress.db",
clearConsole: false,
});
// Add video IDs (from TikTok URL) and/or usernames
scraper.addObjects(["7398323154424171806"], "batch1", "content");
scraper.addObjects(["tiktok", "tagesschau"], "users", "user");
// Scrape: metadata only, or with media (mp4/jpeg/mp3)
await scraper.scrapePending({ scrapeFiles: false }); // metadata only
// await scraper.scrapePending({ scrapeFiles: true }); // also download videos/slides/audio- Content: use
type: "content"and video IDs from the video URL. - Users: use
type: "user"and usernames (with or without@).
Output is written under outputDir:
content_metadata/<video_id>.json– video/post metadatauser_metadata/<username>.json– user profile metadatacontent_files/– mp4, jpeg, mp3 whenscrapeFiles: true
Progress is stored in the SQLite database at progressDbPath (pending/completed/error per ID).
Test
npm testRuns a metadata-only scrape of 1 video + 1 user and checks output files.
API (TypeScript)
TTContentScraper– Main scraper (extendsObjectTracker). Options:waitTime,outputDir,progressDbPath,clearConsole.ObjectTracker– SQLite progress DB:addObject,addObjects,markCompleted,markError,getPendingObjects,getStats,getObjectStatus,getErrorObjects,resetErrorsToPending,resetAllToPending,clearAllData,close.BaseScraper– Low-level:scrapeMetadata(videoId),scrapeUser(username),scrapeBinaries(links).filterTiktokData(raw)– Normalize raw TikTokitemStructinto typed metadata.ObjectStatus– Enum:PENDING,COMPLETED,ERROR,RETRY.
Publish to npm
- Log in:
npm login - From
tiktok-api-ts:npm publish(ornpm publish --access publicfor a scoped package like@your-scope/tiktok-api-unofficial).
If the name tiktok-api-unofficial is taken, set a different name in package.json (e.g. tiktok-scraper-unofficial or @your-username/tiktok-api-unofficial).
Push to GitHub
- Create a new repository on GitHub (e.g.
tiktok_scrapper). - In your project root:
(Usegit remote add origin https://github.com/8dazo/tiktok_scrapper.git git push -u origin mainmasterinstead ofmainif your default branch ismaster.)
License
MIT.
