/TikTok-Api

The Unoffical TikTok API Wrapper In Python

Primary LanguagePythonMIT LicenseMIT

Unoffical TikTok API in Python

This is an unoffical api wrapper for tiktok.com in python. With this api you are able to call most trending and fetch specific user information.

GitHub release (latest by date) Build Status GitHub PyPI - Downloads

Important Information

  • If this API stops working for any reason open an issue.
  • Feel free to mention @davidteather in an issue you open, because I might not see it otherwise.

Getting Started

To get started using this api follow the instructions below.

It is quite a long installation process just for a TikTok api, the first release can be found here and is not as suitable for long term projects, however it may be easier for a day of scraping TikTok, as the installation is much easier.

Despite this, I still recommend you follow this process and use the latest version.

Installing

If you need help installing or run into some error, please open an issue. I will try to help out as much as I can.

Tested with python 3.7.3

pip install TikTokApi

Or install directly from this GitHub repo.

  • You do need to have java installed
  • Download browsermob-proxy here
  • You must add browsermob-proxy/bin to your environment path.
  • Firefox must be installed.
  • You must download the latest geckodriver from mozilla, and include the .exe in your path.

Quick Start Guide

Here's a quick bit of code to get the most recent trending on TikTok

from tiktok import TikTokapi

api = TikTokapi(path_to_browsermob_directory)
# path_to_browsermob_directory - String - should be the path from the directory you are running from the code to the extracted zip file of [browsermob-proxy](https://bmp.lightbody.net/)
# Will Get the 10 most recent trending on the tiktok trending page
api.trending(10)

Detailed Documentation

The TikTok class
# Variable set like
api = TikTokapi(path_to_browsermob_directory, headless=False)

path_to_browsermob_directory - String - should be the path from the directory you are running from the code to the extracted zip file of browsermob-proxy headless - True/False - True means it will run a headless firefox browser, could be detected by TikTok, however it is more convienent. Default = False.

The Trending Method
# Where count is how many result you want
# Verbose is optional, default=0. Set it to 1 to get more information
api.trending(count, verbose)

Trending returns an array of json objects. Example structure here

JSON object tree here

The userPosts Method
# Where count is how many results you want
# Verbose is optional, default=0. Set it to 1 to get more information
# userid is the tiktok userid, can be found through response json tree or in the tiktok url
api.userPosts(userid, count, verbose)

Since this isn't an offical TikTok API the TikTok servers don't know what to do. This method specifically will throw a lot of errors if you have verbose on. It takes a lot longer than trending, however it will still end up working. Just give it a few minutes.

Trending returns an array of json objects. Example structure here

It has the same JSON object tree as trending. It's here anyways.

The search_by_hashtag Method
api.search_by_hashtag(hashtag, count=10)

hashtag - A string of the hashtag without the # mark. Ex: hashtag = "funny"

count - The number of results you want

Since this isn't an offical TikTok API the TikTok servers don't know what to do with my bad solutions, this takes a bit longer as it needs to find the hashtagID and stuff.

Search by hashtag returns an array of json objects. Example structure here

It has the same JSON object tree as trending. It's here anyways.

The get_trending_hashtags Method
api.get_trending_hashtags()

This returns the 4 displayed trending hashtags in an array, this does change on every new instance of the api as it changes on page refreshes.

Built With

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details