intro-to-python icon indicating copy to clipboard operation
intro-to-python copied to clipboard

TikTok API

Open s2t2 opened this issue 3 years ago • 0 comments

There is a wrapper package but it's kind of buggy / not well documented.

  • https://github.com/davidteather/TikTok-Api

It doesn't work in Colab / notebooks.

  • https://github.com/davidteather/TikTok-Api/issues/882

Some endpoints don't seem to work locally, but some do.

  • https://github.com/davidteather/TikTok-Api/issues/928

Installation

Depends on lower-level "playwright" dependency:

pip install TikTokApi==5.2.2
python -m playwright install

Usage

Context manager approach:

with TikTokApi() as api:
    tag = api.hashtag(name="funny")

    print(tag.info())

    for video in tag.videos():
        print(video.id)

Alternative approach:

api = TikTokApi()
print(dir(api))
print("-------------")

tag = api.hashtag(name="funny")
print(type(tag))
print(tag.info())

for video in tag.videos():
    print(type(video)) #> <class 'TikTokApi.api.video.Video'>
    print(video.id)

# if not using the "with" context manager approach, manually close:
api.shutdown()

s2t2 avatar Aug 05 '22 01:08 s2t2