Giter Club home page Giter Club logo

tiktok-api's Introduction

Unofficial TikTok API in Python

This is an unofficial api wrapper for TikTok.com in python. With this api you are able to call most trending and fetch specific user information as well as much more.

DOI LinkedIn Sponsor Me GitHub release (latest by date) GitHub Downloads Support Server

This api is designed to retrieve data TikTok. It can not be used post or upload content to TikTok on the behalf of a user. It has no support any user-authenticated routes, if you can't access it while being logged out on their website you can't access it here.

Sponsors

These sponsors have paid to be placed here and beyond that I do not have any affiliation with them, the TikTokAPI package will always be free and open-source. If you wish to be a sponsor of this project check out my GitHub sponsors page.

Table of Contents

Upgrading from V5 to V6

Documentation

You can find the full documentation here

Getting Started

To get started using this API follow the instructions below.

Note: If you want to learn how to web scrape websites check my free and open-source course for learning everything web scraping

How to Support The Project

  • Star the repo ๐Ÿ˜Ž
  • Consider sponsoring me on GitHub
  • Send me an email or a LinkedIn message telling me what you're using the API for, I really like hearing what people are using it for.
  • Submit PRs for issues :)

Installing

Note: Installation requires python3.9+

If you run into an issue please check the closed issues on the github, although feel free to re-open a new issue if you find an issue that's been closed for a few months. The codebase can and does run into similar issues as it has before, because TikTok changes things up.

pip install TikTokApi
python -m playwright install

If you would prefer a video walk through of setting up this package YouTube video just for that. (is a version out of date, installation is the same though)

If you want a quick video to listen for TikTok Live events in python.

Docker Installation

Clone this repository onto a local machine (or just the Dockerfile since it installs TikTokApi from pip) then run the following commands.

docker pull mcr.microsoft.com/playwright:focal
docker build . -t tiktokapi:latest
docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py

Note this assumes your script is named your_script.py and lives in the root of this directory.

Common Issues

Please don't open an issue if you're experiencing one of these just comment if the provided solution do not work for you.

  • Browser Has no Attribute - make sure you ran python3 -m playwright install, if your error persists try the playwright-python quickstart guide and diagnose issues from there.

Quick Start Guide

Here's a quick bit of code to get the most recent trending videos on TikTok. There's more examples in the examples directory.

Note: If you want to learn how to web scrape websites check my free and open-source course for web scraping

from TikTokApi import TikTokApi
import asyncio
import os

ms_token = os.environ.get("ms_token", None) # get your own ms_token from your cookies on tiktok.com

async def trending_videos():
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
        async for video in api.trending.videos(count=30):
            print(video)
            print(video.as_dict)

if __name__ == "__main__":
    asyncio.run(trending_videos())

To directly run the example scripts from the repository root, use the -m option on python.

python -m examples.get_trending

You can access the full data dictionary the object was created from with .as_dict. On a video this may look like this. TikTok changes their structure from time to time so it's worth investigating the structure of the dictionary when you use this package.

Upgrading from V5 to V6

All changes will be noted on V6.0.0 if you want more information.

Changes & Motivations

  • Maintainability
    • Was getting difficult to maintain with how TikTok was directly detecting HTTP requests.
    • Switched to using a pool of async playwright pages to make it more difficult to detect, and hopefully easier to maintain in the future
  • Async
    • It's been asked for a lot, and now fully async needed especially since the package is using a pool of playwright instances
  • User Flexibility
    • Added a lot of function argument options that should be much more explicit than what was done previously.
    • Hopefully if something is broken there's a workaround without having to modify the package itself (although if you do notice an issue please open an issue or submit a PR)
  • Documentation
    • Goes with user flexibility a little bit but switched over to sphinx documentation for more explicit content
    • If you run into an issue or are confused please open a github issue or submit a PR to fix documentation, it's always welcome! ๐Ÿค 

Upgrading Examples

The biggest change is that everything is now async. You can see above how you might want to call an async function in python as well as the examples directory for more examples.

tiktok-api's People

Contributors

abhint avatar andrearama avatar barakplasma avatar c4l1c0 avatar coloradohusky avatar crazygmr101 avatar ctaity avatar davidteather avatar dependabot-preview[bot] avatar dereklowlind avatar deus-developer avatar dj2ball avatar dronavallipranav avatar dylancaponi avatar erhosen avatar hoylemd avatar isaackogan avatar josbraden avatar muffinfox avatar nightduck avatar olitomas avatar s1ddly avatar sammeeey avatar schrobot avatar shiqwang avatar slouchd avatar vdemay avatar wixome avatar xodarap avatar yoavz avatar

Stargazers

 avatar  avatar

Forkers

dcareem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.