Coder Social home page Coder Social logo

davidteather / tiktok-api Goto Github PK

View Code? Open in Web Editor NEW
4.4K 82.0 901.0 25.53 MB

The Unofficial TikTok API Wrapper In Python

Home Page: https://davidteather.github.io/TikTok-Api

License: MIT License

Python 98.75% Dockerfile 0.13% Makefile 0.52% Batchfile 0.60%
tiktok-api python api trending tiktok-scraper tiktokapi tiktok-downloader tiktok-trending-page tiktok-python tiktok-automation

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.

  • API methods returning Coroutine - many of the API's methods are async so make sure your program awaits them for proper functionality

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.trending_example

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 bendavidsteel 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 faydspeare avatar hoylemd avatar isaackogan avatar josbraden avatar muffinfox avatar olitomas avatar s1ddly avatar sammeeey avatar schrobot avatar shiqwang avatar vdemay avatar wixome avatar xodarap avatar yoavz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiktok-api's Issues

How do I install???

Hi, I've installed browsermob proxy, java and everything else. Where do I save the actual TikTok-Api-master folder!? Thanks for the help! @davidteather

[BUG] Can't Download more than 10 videos

Describe the bug

Even with the variable results setted, the code can't show more than 10 results
The buggy code

from TikTokApi import TikTokapi

# Starts The Api Class
api = TikTokapi("browsermob-proxy/bin/browsermob-proxy")

# The Number of trending TikToks you want to be displayed
results = 20

# Searches for the top trending hashtag of TikTok
result = api.search_by_hashtag("meme")

for tiktok in result:
    # Prints the text of the tiktok
    print(tiktok['itemInfos']['text'])

print(len(result))
api.quit_browser()

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context

[ImportError]

Hi David,

Thanks for making this! I am however having some issues with importing, I am consistently getting this issue "ImportError: cannot import name 'TikTokApi' from 'TikTokApi' (/usr/local/lib/python3.7/site-packages/TikTokApi/init.py)"

Any idea why?

Thanks for your effort!

ERROR Message when running gettrending.py

Hello! I was able to get everything working up to this point. When I run gettrending.py the browser window opens and begins to load the page, then I get this error message.

Traceback (most recent call last):
File "gettrending.py", line 11, in
trending = api.trending(results)
File "C:\Users\steee\Anaconda3\envs\tiktok\lib\site-packages\TikTokApi\tiktok.py", line 229, in trending
if count > len(response) and str(data['body']['hasMore']) == "True":
KeyError: 'body'

[BUG] Could not locate hashtag ID

Describe the bug


Traceback (most recent call last):
  File ".\getHashtag.py", line 10, in <module>
    result = api.search_by_hashtag("xmas")
  File "C:\Users\loren\AppData\Local\Programs\Python\Python37\lib\site-packages\TikTokApi\tiktok.py", line 124, in search_by_hashtag
    raise Exception("Could not locate hashtag ID: Tried " + str(tries) + " times")
Exception: Could not locate hashtag ID: Tried 10 times

The buggy code


from TikTokApi import TikTokapi

# Starts The Api Class
api = TikTokapi("browsermob-proxy/bin/browsermob-proxy")

# The Number of trending TikToks you want to be displayed
results = 10

# Searches for the top trending hashtag of TikTok
result = api.search_by_hashtag("xmas")

for tiktok in result:
    # Prints the text of the tiktok
    print(tiktok['itemInfos']['text'])

print(len(result))
api.quit_browser()

Getting post information directly

Assuming we have the id of a post we want to check, is there a way anyone knows that we can use to get more information about an individual post directly rather than querying the user and trawling through their posts to match the id. This would save on potentially a lot of additional requests.

Thanks!

[BUG] certificate error when running example code

Describe the bug

I'm getting a certificate error when trying to run the Quickstart.

The buggy code

Python 3.7.6 (default, Jan  8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from TikTokApi import TikTokApi
>>> results=10
>>> api=TikTokApi()
>>> trending=api.trending(results)
[W:pyppeteer.chromium_downloader] start chromium download.
Download may take a few minutes.
Traceback (most recent call last):
  File "D:\anaconda\lib\site-packages\urllib3\contrib\pyopenssl.py", line 485, in wrap_socket
    cnx.do_handshake()
  File "D:\anaconda\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "D:\anaconda\lib\site-packages\OpenSSL\SSL.py", line 1671, in _raise_ssl_error
    _raise_current_error()
  File "D:\anaconda\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "D:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "D:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn
    conn.connect()
  File "D:\anaconda\lib\site-packages\urllib3\connection.py", line 360, in connect
    ssl_context=context,
  File "D:\anaconda\lib\site-packages\urllib3\util\ssl_.py", line 370, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "D:\anaconda\lib\site-packages\urllib3\contrib\pyopenssl.py", line 491, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\anaconda\lib\site-packages\TikTokApi\tiktok.py", line 62, in trending
    b = browser(api_url)
  File "D:\anaconda\lib\site-packages\TikTokApi\browser.py", line 27, in __init__
    asyncio.get_event_loop().run_until_complete(self.start())
  File "D:\anaconda\lib\asyncio\base_events.py", line 583, in run_until_complete
    return future.result()
  File "D:\anaconda\lib\site-packages\TikTokApi\browser.py", line 30, in start
    self.browser = await pyppeteer.launch(self.options)
  File "D:\anaconda\lib\site-packages\pyppeteer\launcher.py", line 305, in launch
    return await Launcher(options, **kwargs).launch()
  File "D:\anaconda\lib\site-packages\pyppeteer\launcher.py", line 119, in __init__
    download_chromium()
  File "D:\anaconda\lib\site-packages\pyppeteer\chromium_downloader.py", line 146, in download_chromium
    extract_zip(download_zip(get_url()), DOWNLOADS_FOLDER / REVISION)
  File "D:\anaconda\lib\site-packages\pyppeteer\chromium_downloader.py", line 85, in download_zip
    data = http.request('GET', url, preload_content=False)
  File "D:\anaconda\lib\site-packages\urllib3\request.py", line 76, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File "D:\anaconda\lib\site-packages\urllib3\request.py", line 97, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "D:\anaconda\lib\site-packages\urllib3\poolmanager.py", line 330, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "D:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 760, in urlopen
    **response_kw
  File "D:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 760, in urlopen
    **response_kw
  File "D:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 760, in urlopen
    **response_kw
  File "D:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "D:\anaconda\lib\site-packages\urllib3\util\retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='storage.googleapis.com', port=443): Max retries exceeded with url: /chromium-browser-snapshots/Win_x64/588429/chrome-win32.zip (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

Desktop (please complete the following information):

  • OS: Windows 10
  • Version 3.1.0

UserPosts are not working

Trying the following code from the example.

from TikTokApi import TikTokapi

Starts The Api Class

api = TikTokapi("C:\Tfs\Projects\TimeBucksCode\tiktok\browsermob-proxy-2.1.4-bin\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat")

The Number of trending TikToks you want to be displayed

results = 10

userPosts = api.userPosts("khaleelabdullah_")

for tiktok in userPosts:
print(tiktok)

#print(len(trending))

api.quit_browser()

User posts are not loading, probably they have changed something

image

[BUG] userPosts() does not return posts

Requesting user's posts do not seem to respond when requesting using api.userPosts(username="username")

buggy code

import requests
import random
import string
import urllib.request
import glob
import os
import mimetypes
from TikTokApi import TikTokapi

api = TikTokapi("browsermob-proxy-2.1.4/bin/browsermob-proxy")
print(api.userPosts(username="levelsofpiano"))

Expected behavior

I would assume a JSON response describing the posts made by the user "levelsofpiano".

Actual behavior

Browser loads user's page, but does not load the user's posts.

Screenshots

Screen Shot 2020-01-12 at 9 53 41 AM

Desktop (please complete the following information):

  • OS: OSX 10.12.5
  • Browser: Chrome
  • Version: 79.0.3945.117
  • browsermob version 2.1.4
  • Chrome driver matches Chrome version

Additional context

No errors are produced on the console. I left it running for a good 20 minutes and got no response, so it's safe to say that the program hangs on this command.

Runtime error in Example

Hi David,
thanks for making this, I´m really looking forward to the hashtag- API.

In the meantime I updated my version of TikTokApi and now I get a runtime error when running the example code. Do you have any idea why?
Thank you so much in advance!
Julia

Bildschirmfoto 2020-05-10 um 18 49 15

I think there is still an issue with getting more than 68 videos

I think the issue is still present because when I invoke trending(100) let's say, the len() function of the data it returns never exceeds more than 65-68 videos. Also in line 32, in the if statement the two urls are the same, but one has a space so the signature was never returned. I got it working by setting one of the two links to m.tiktok.com/.... .

Maybe I didn't use the function properly or something?

error with web driver

Hello,
What webdriver you actually used on your api?

if gecko / firefox why I got message when I run : example/getTrending.py,

C:\xampp\htdocs\tiktokpy\examples>python getTrending.py
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "getTrending.py", line 4, in
api = TikTokapi("C:/xampp/htdocs/tiktokpy/browsermob/bin/browsermob-proxy.bat", headless=False)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TikTokApi\tiktok.py", line 53, in init
self.driver = webdriver.Chrome(chrome_options=chromeProfile)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in init
self.service.start()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

how to resolve this error?

[BUG] "Exception: Could not locate user/hashtag ID: Tried 10 times"

Hi, thank you for your time and effort in this.

I tried to run the various examples scripts you provided, only getTrending.py works. The other raises the exception in the title ("Exception: Could not locate user/hashtag ID: Tried 10 times"), as if the id was None.
The same with scripts written by me, only trending works fine.

Using:

  • Python: 3.7
  • OS: Windows 10
  • Browser: Firefox 72.0.2 (64 bit)

[BUG]

Do you know how can I get video views count? I only see on the api likes count, shares count and comment count.

Getting This Error - 'TikTokapi' object has no attribute 'signature'

@davidteather

Get this error on console-

New class reference, finding valid signature. This might take a minute.
Traceback (most recent call last):
File "getTrending.py", line 11, in
trending = api.trending(results)
File "C:\Users\Sagar\Downloads\TikTok-Api-master\tiktok.py", line 49, in trend
ing
self.signature
AttributeError: 'TikTokapi' object has no attribute 'signature'

[BUG] 200 response code for trending video

Describe the bug

The request to "https://m.tiktok.com/share/item/list?secUid=&id=&type=5&count=30&minCursor=0&maxCursor=0&shareUid=&_signature=" + self.signature always results in a 200 code

The buggy code

The trending video call

trending = api.trending(count=30)
        url = "https://m.tiktok.com/share/item/list?secUid=&id=&type=5&count=30&minCursor=0&maxCursor=0&shareUid=&_signature=" + self.signature
        r = requests.get(url, headers={"method": "GET",
                                       "accept-encoding": "gzip, deflate, br",
                                       "Referer": self.referer,
                                       "user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"}
                         )

        data = r.json()
        response = []
        if data["statusCode"] == 0:
            # run code
       elif data['statusCode'] == 200:
           print('error')

Expected behavior

Earlier today, it was working earlier but it suddenly stopped working. Possibly they are rate limiting me based on IP, but I was not sure.

Desktop (please complete the following information):

  • Windows 10 with the most recent chromedriver, browsermod and TikTok-Api

Status 200 is always thrown

Currently when I run the trending function, it never returns a status 0. I believe that the signature found via selenium is not a totally valid one, and if you go to the tiktok trending website with a headed browser you can see the videos never really load

chromedriver needs to be in path.

Hi @davidteather. First of all my congratulation. Your work is great. Just one question:
As I try to run my first code:

==========
from TikTokApi import TikTokapi

api = TikTokapi('/Users/mariadaniello/Desktop/browsermob-proxy-2.1.4/bin/browsermob-proxy')

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

Will Get the 10 most recent trending on the tiktok trending page

api.trending(10)`

The IDLE returns me the following error:

===========
Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

My chromedriver, as a norml MacOs user, is in /usr/local/bin/. Could you please tell me how to solve this iussue? Thank you.

How can i download video ?

hello there ,
i'm unaware of python but i'm looking for this.
how can i video download with URL and how can i get "video_id" using URL?

hope i will get some help from you.

[BUG]search_by_hashtag

I've just started using that api, using the function
result = api.search_by_hashtag('simpaticissimi', count=10)
the browser gives me the results about "simpaticissimi" tag, but the code crashed give me into the console that error:
New class reference, finding valid signature. This might take a minute. Found signature, continuing. Traceback (most recent call last): File "botticelliAPI.py", line 7, in <module> result = api.search_by_hashtag('simpaticissimi', count=10) File "/usr/lib/python3.7/site-packages/TikTokApi/tiktok.py", line 193, in search_by_hashtag raise Exception('Unable to locate the hashtag ID') Exception: Unable to locate the hashtag ID

What that meaning?
How to fix it to run the code under the api call?

[BUG]

Hey all,
I am getting the below error when trying to run the quick start code in pycharm. Can anyone help please?

Error:

C:\USERS\USER1\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/USER1/PycharmProjects/untitled/testtiktok.py
2020-04-19 18:04:41.351 | INFO | tiktok_bot.api.api:list_for_you_feed:76 - Getting 25 posts from your feed
List for you feed: 0%| | 0/25 [00:00<?, ?it/s]
Traceback (most recent call last):
File "C:/Users/USER1/PycharmProjects/untitled/testtiktok.py", line 6, in
my_feed = bot.list_for_you_feed(count=25)
File "C:\Users\USER1\PycharmProjects\untitled\venv\lib\site-packages\tiktok_bot\bot\bot.py", line 60, in list_for_you_feed
feed = self.api.list_for_you_feed(count=count)
File "C:\Users\USER1\PycharmProjects\untitled\venv\lib\site-packages\tiktok_bot\api\api.py", line 87, in list_for_you_feed
response = self._list_for_you_feed(list_feed_request=request)
File "C:\Users\USER1\PycharmProjects\untitled\venv\lib\site-packages\tiktok_bot\api\api.py", line 68, in list_for_you_feed
feed = ListForYouFeedResponse(**response.json())
File "C:\Users\USER1\PycharmProjects\untitled\venv\lib\site-packages\httpx\models.py", line 930, in json
return jsonlib.loads(self.text, **kwargs)
File "C:\Users\USER1\AppData\Local\Programs\Python\Python38-32\lib\json_init
.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\USER1\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\USER1\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Process finished with exit code 1


List of trending sounds

Hello,

Would it be possible to implement an API request in order to grab the trending sounds with data associated with that sound? I know the method you have now does not grab the sound due to an incorrect signature. I'm not familiar with the signatures but if there is a new endpoint to get it I can try implementing it into the project.

Page doesn't load

Describe the bug

Using the simple code example given on your github I tried to run the script, everything works but after opening the link, it does not load the page content. It is stuck on the loading screen

The buggy code

from tiktok import TikTokapi
api = TikTokapi("mypath")
api.trending(10)

Expected behavior

it should load the trending videos but it is stuck on loading screen
image

Desktop (please complete the following information):

  • Windows 10
  • Chrome
  • version-79.0.3945.88
    Additional context

Please let me know if we can somehow make it load the page, I have tried many methods to somehow make it work but still no luck. I hope you can suggest something or update your code here to make it work.

Digg Count

For the userpost function, what does "diggcount" refer to? does this mean the number of likes or the number of views on the video?

Update JSON Structure [HELP]

Describe the bug

In the previous version of this API i use the following code to create an array with all the urls

The buggy code

for tiktok in trending:
    videoURL = tiktok["itemInfos"]["video"]["urls"]
    videoname = "downloaded/" + str(prevloops) + ".mp4"
    wget.download(videoURL[0], videoname)
    open("downloaded/concat.txt", 'a').write("file " + str(prevloops) + ".mkv" + "\n")
    clip = VideoFileClip(videoname)
    d = ( clip.duration )
    open("downloaded/durata.txt", 'a').write(str(d) + "\n")
    os.system("ffmpeg -loglevel panic -i downloaded/" + str(prevloops) +  ".mp4" + " -c copy -map 0 downloaded/" + str(prevloops) + ".mkv")
    prevloops += 1

Expected behavior

Download the videos from a target hashtag

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10 64bit
  • Browser Chrome 78.0.3904.108

Additional context

Here the error in the console

Traceback (most recent call last):
  File "downloader.py", line 40, in <module>
    videoURL = tiktok["itemInfos"]["video"]["urls"]
KeyError: 'itemInfos'

I think this error is due to the different json structure, I tried to use the new one but didn't succeed

Getting error connecting to browsermob-proxy

I am getting this error when running the API on CentOS 7.

[root@backups tiktok]# python3.6 test.py
New class reference, finding valid signature. This might take a minute.
Traceback (most recent call last):
File "test.py", line 5, in
api = TikTokapi("/root/tiktok/browsermob-proxy-2.1.4/bin/browsermob-proxy")
File "/usr/local/lib/python3.6/site-packages/TikTokApi/tiktok.py", line 26, in init
self.server.start()
File "/usr/local/lib/python3.6/site-packages/browsermobproxy/server.py", line 127, in start
raise ProxyServerError("Can't connect to Browsermob-Proxy")
browsermobproxy.exceptions.ProxyServerError: Can't connect to Browsermob-Proxy

Can't connect to Browsermob-Proxy

Describe the bug

Followed all your instruction but still getting the following an error

The buggy code

`from TikTokApi import TikTokapi

Starts T

api = TikTokapi("/Applications/Anaconda/anaconda3/lib/python3.7/site-packages/browsermob-proxy/bin/browsermob-proxy")

The Number of trending TikToks you want to be displayed

results = 10
trending = api.trending(results)

for tiktok in trending:
# Prints the text of the tiktok
print(tiktok['itemInfos']['text'])

print(len(trending))
api.quit_browser()`

Error

`---------------------------------------------------------------------------
ProxyServerError Traceback (most recent call last)
in
2
3 # Starts T
----> 4 api = TikTokapi("/Applications/Anaconda/anaconda3/lib/python3.7/site-packages/browsermob-proxy/bin/browsermob-proxy")
5
6 # The Number of trending TikToks you want to be displayed

/Applications/Anaconda/anaconda3/lib/python3.7/site-packages/TikTokApi/tiktok.py in init(self, browsermobDirectory, headless, manualSignature)
25 path=browsermobDirectory, options=dictf)
26 # "browsermob-proxy/bin/browsermob-proxy"
---> 27 self.server.start()
28 time.sleep(1)
29 self.proxy = self.server.create_proxy()

/Applications/Anaconda/anaconda3/lib/python3.7/site-packages/browsermobproxy/server.py in start(self, options)
125 if count == retry_count:
126 self.stop()
--> 127 raise ProxyServerError("Can't connect to Browsermob-Proxy")
128
129 def stop(self):

ProxyServerError: Can't connect to Browsermob-Proxy`

Desktop (please complete the following information):

  • OS: [macOS Mojave 10.14.6]
  • Browser [chrome]
  • Version [79.0.3945.130 (Official Build) (64-bit)]

Additional context

Downloaded all the files that you recommend including browsermob (and created the right folder) and also geckodriver

Spent hours and still cant get it to work.
Thanks.

Can't import the Tiktokapi library

Describe the bug

A clear and concise description of what the bug is.

The buggy code

Please insert the code that is throwing errors or is giving you weird unexpected results.

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context

Add any other context about the problem here.

[BUG]

Describe the bug

DevTools listening on ws://127.0.0.1:55641/devtools/browser/414bc91b-8f0a-4365-98a8-0ffb1521f769
Traceback (most recent call last):
  File ".\test.py", line 13, in <module>
    result = api.search_by_hashtag(trending_tags[0])
IndexError: list index out of range

The buggy code

from TikTokApi import TikTokapi

# Starts The Api Class
api = TikTokapi("browsermob-proxy/bin/browsermob-proxy")

# The Number of trending TikToks you want to be displayed
results = 10

# Gets trending hashtags
trending_tags = api.get_trending_hashtags()

# Searches for the top trending hashtag of TikTok
result = api.search_by_hashtag(trending_tags[0])

for tiktok in result:
    # Prints the text of the tiktok
    print(tiktok['itemInfos']['text'])

print(len(result))

Expected behavior

Updated to the latest version of TikTokApi, used an example to test them, but seems to be stuck on loading tiktok feed inside chrome browser

Screenshots

https://snipboard.io/GtqST7.jpg

Desktop (please complete the following information):

  • OS: [Windows 10 64]
  • Browser [chrome]
  • Version [79.0.3945.88]

Additional context

Add any other context about the problem here.

just a dummy question relating TikTok Api @davidteather

Hi @davidteather, I'm a newbie on coding, spending pretty much time a day on learning python. Currently, I have a task to set up an application on my website that would be able to interact with the TikTok users' content. Like a user of my website would enter his/her username and the application displays his/her TikTok posts, then the user, let's say, chooses some of his/her posts and I get links to the posts that the user would have chosen.

So the question is can your TikTok-API help somehow on the task I currently have. And yes, I know this is pretty dummy and is just a pain in the ass but every single help or hint is highly appreciated. Thanks in advance.

browsermob-proxy, geckodriver and Firefox installation, setup and running

Hi David,

Thank you for your fantastic work and could you please give an explanation about how to know if browsermob-proxy, geckodriver and Firefox run together successfully?
any configuration or startup order requirements on them.

I followed the Installing instructions and was trying to run the example-getTrending.py first. But get errors:

C:\Users\Owner.virtualenvs\TikTok-GPkkHXDp\Scripts\python.exe C:/Users/Owner/PycharmProjects/TikTok/examples/getTrending.py
New class reference, finding valid signature. This might take a minute.
Traceback (most recent call last):
File "C:/Users/Owner/PycharmProjects/TikTok/examples/getTrending.py", line 8, in
trending = api.trending(results)
File "C:\Users\Owner.virtualenvs\TikTok-GPkkHXDp\lib\site-packages\TikTokApi\tiktok.py", line 246, in trending
self.signature
AttributeError: 'TikTokapi' object has no attribute 'signature'

Process finished with exit code 1

I found logs of the above servers, looks like they didn't run successfully.

bmp.log

[INFO 2019-11-04T22:56:28,200 net.lightbody.bmp.proxy.Main] (main) Starting BrowserMob Proxy version 2.1.4
[INFO 2019-11-04T22:56:28,283 org.eclipse.jetty.util.log] (main) jetty-7.x.y-SNAPSHOT
[INFO 2019-11-04T22:56:29,098 org.eclipse.jetty.util.log] (main) started o.e.j.s.ServletContextHandler{/,null}
[INFO 2019-11-04T22:56:29,495 org.eclipse.jetty.util.log] (main) Started [email protected]:8090
[INFO 2019-11-04T22:56:33,616 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp1503660218-21) Starting proxy at address: 0.0.0.0/0.0.0.0:8091
[INFO 2019-11-04T22:56:33,688 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp1503660218-21) Proxy listening with TCP transport
[INFO 2019-11-04T22:56:34,787 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp1503660218-21) Proxy started at address: /0:0:0:0:0:0:0:0:8091
[INFO 2019-11-04T22:56:53,795 org.littleshoot.proxy.impl.ClientToProxyConnection] (LittleProxy-0-ClientToProxyWorker-7) (AWAITING_INITIAL) [id: 0x0d4e71a9, L:/0:0:0:0:0:0:0:1:8091 - R:/0:0:0:0:0:0:0:1:57744]: An IOException occurred on ClientToProxyConnection: An established connection was aborted by the software in your host machine
[INFO 2019-11-04T22:56:55,311 org.littleshoot.proxy.impl.ClientToProxyConnection] (LittleProxy-0-ClientToProxyWorker-0) (NEGOTIATING_CONNECT) [id: 0xcffd8c37, L:/0:0:0:0:0:0:0:1:8091 - R:/0:0:0:0:0:0:0:1:57746]: An IOException occurred on ClientToProxyConnection: An established connection was aborted by the software in your host machine
[INFO 2019-11-04T22:56:55,323 org.littleshoot.proxy.impl.ProxyToServerConnection] (LittleProxy-0-ProxyToServerWorker-0) (DISCONNECTED) [id: 0x9418bdfc, L:0.0.0.0/0.0.0.0:57748]: Connection to upstream server failed java.nio.channels.ClosedChannelException: null
at io.netty.handler.ssl.SslHandler.channelInactive(...)(Unknown Source) ~[browsermob-dist-2.1.4.jar:?]

server.log

Running BrowserMob Proxy using LittleProxy implementation. To revert to the legacy implementation, run the proxy with the command-line option '--use-littleproxy false'.
[INFO 2019-11-04T22:56:28,200 net.lightbody.bmp.proxy.Main] (main) Starting BrowserMob Proxy version 2.1.4
[INFO 2019-11-04T22:56:28,283 org.eclipse.jetty.util.log] (main) jetty-7.x.y-SNAPSHOT
[INFO 2019-11-04T22:56:29,098 org.eclipse.jetty.util.log] (main) started o.e.j.s.ServletContextHandler{/,null}
[INFO 2019-11-04T22:56:29,495 org.eclipse.jetty.util.log] (main) Started [email protected]:8090
[INFO 2019-11-04T22:56:33,616 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp1503660218-21) Starting proxy at address: 0.0.0.0/0.0.0.0:8091
[INFO 2019-11-04T22:56:33,688 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp1503660218-21) Proxy listening with TCP transport
[INFO 2019-11-04T22:56:34,787 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp1503660218-21) Proxy started at address: /0:0:0:0:0:0:0:0:8091
[INFO 2019-11-04T22:56:53,795 org.littleshoot.proxy.impl.ClientToProxyConnection] (LittleProxy-0-ClientToProxyWorker-7) (AWAITING_INITIAL) [id: 0x0d4e71a9, L:/0:0:0:0:0:0:0:1:8091 - R:/0:0:0:0:0:0:0:1:57744]: An IOException occurred on ClientToProxyConnection: An established connection was aborted by the software in your host machine
[INFO 2019-11-04T22:56:55,311 org.littleshoot.proxy.impl.ClientToProxyConnection] (LittleProxy-0-ClientToProxyWorker-0) (NEGOTIATING_CONNECT) [id: 0xcffd8c37, L:/0:0:0:0:0:0:0:1:8091 - R:/0:0:0:0:0:0:0:1:57746]: An IOException occurred on ClientToProxyConnection: An established connection was aborted by the software in your host machine
[INFO 2019-11-04T22:56:55,323 org.littleshoot.proxy.impl.ProxyToServerConnection] (LittleProxy-0-ProxyToServerWorker-0) (DISCONNECTED) [id: 0x9418bdfc, L:0.0.0.0/0.0.0.0:57748]: Connection to upstream server failed java.nio.channels.ClosedChannelException: null
at io.netty.handler.ssl.SslHandler.channelInactive(...)(Unknown Source) ~[browsermob-dist-2.1.4.jar:?]

======
geckodriver.log

1572879398947 mozrunner::runner INFO Running command: "C:\Program Files\Mozilla Firefox\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\Users\Owner\AppData\Local\Temp\rust_mozprofilewtK5Yc"
1572879402275 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: mozillaAddons
1572879402276 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: telemetry
1572879402276 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: resource://pdf.js/
1572879402277 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: about:reader*
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1572879408577 Marionette INFO Listening on port 57711
1572879408762 Marionette WARN TLS certificate errors will be ignored for this session
1572879413597 Marionette INFO Stopped listening on port 57711
[Child 10436, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1572401533/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
[Child 10436, Chrome_ChildThread] [Child 8216, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1572401533/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
console.error: (new Error("Transaction canceled due to a closed connection.", "resource://gre/modules/Sqlite.jsm", 613))
[GPU 10888, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1572401533/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, li
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost

ne 341

###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv

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.