TikTok-Api is an unofficial, asynchronous Python 3 wrapper for interacting with the TikTok API. It leverages Playwright for headless browser automation to bypass bot detection and fetch data. Currently at version 7.3.3, it has a frequent release cadence, often with minor updates, but also introduces significant changes to handle TikTok's evolving anti-bot measures.
pip install tiktokapiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to fetch trending TikTok videos. It highlights the use of `ms_token` for authentication/stability and the asynchronous nature of the library. Remember to run `playwright install` first.
Update your code to expect and process `Playlist` objects instead of raw dictionaries when calling `user().info`.
Use a valid `ms_token` (from your browser cookies), configure proxies (especially with `proxyproviders` for v7.2.0+), set `headless=False` during development/debugging, and consider using custom `browser_args` to mimic a real user.
Ensure all `TikTokApi` calls are `await`ed and your main script uses `asyncio.run()` or is part of an existing event loop.
Run `playwright install` in your terminal to download and configure the required browser engines (Chromium, Firefox, WebKit).
Obtain an `ms_token` from your browser's TikTok cookies and pass it to the `TikTokApi` constructor (e.g., `TikTokApi(ms_token='your_token')`).
Run `pip install playwright` to install the package.
Run `playwright install` in your terminal to download the required browsers.
Wrap your asynchronous `TikTokApi` calls within an `async def` function and execute it using `asyncio.run(your_async_function())`.
Ensure you are using a valid, recent `ms_token`. Try `headless=False` for debugging. Consider using proxies and setting `num_sessions` to 1 initially for stability. Check your internet connection.
Implement robust anti-bot strategies: use a valid `ms_token`, integrate with `proxyproviders` (v7.2.0+), try different `browser_args`, and consider adding delays between requests. Reducing `count` in data fetching methods might also help.