Skip to main content

The Unoffical TikTok API Wrapper in Python 3.

Project description

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_Video_By_Url Method
api.getVideoByUrl(video_url, return_bytes=0)

video_url - The video you want to get url.

return_bytes - The default value is 0, when it is set to 1 the function instead returns the bytes from the video rather than just the direct url.

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

Project details


Release history Release notifications | RSS feed

This version

2.1.6

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TikTokApi-2.1.6.tar.gz (7.0 kB view details)

Uploaded Source

File details

Details for the file TikTokApi-2.1.6.tar.gz.

File metadata

  • Download URL: TikTokApi-2.1.6.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for TikTokApi-2.1.6.tar.gz
Algorithm Hash digest
SHA256 b0641ad7bc39e40c24f76ba419cbe06abba8cf2a23e17baf7abe4986b54243f9
MD5 c0f79d617dd7861bcb5e079f488bd14d
BLAKE2b-256 2b44d164cac8006e86b55434aa66e6fb5e9833b441c0d49559e158b1c7af2512

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page