davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.75k stars 960 forks source link

Grabbing Trending TikToks No Longer Working. PyTest tests\test_trending.py Failing #1084

Open M-Minkov opened 10 months ago

M-Minkov commented 10 months ago

Grabbing trending TikToks no longer working PyTest code can be found in the repository underneath: tests\test_trending.py And it can be seen to be failing, every time it is ran. Specifically, it tries to grab the top 100 videos, but returns 0 videos.

From my understanding the way we try to grab the video IDs/Urls is probably at fault here. Maybe something changed on the website, and the specific HTML or JavaScript tags we're searching for doesn't work anymore. (For context, I have my own Selenium-based solution that I've been creating, and it's managing just fine to grab videos)

When debugging, and going into the code myself, I've noticed this section underneath TikTokApi\api\trending.py

resp = await Trending.parent.make_request(
                url="https://www.tiktok.com/api/recommend/item_list/",
                params=params,
                headers=kwargs.get("headers"),
                session_index=kwargs.get("session_index"),
            )

in this case, going deeper into the code for parent.make_request(), I got to a level where PlayWright was running fetch requests, and getting promises using JavaScript, however, the only thing that's returned in the end is resp = {'status_code': 0}. But it can be seen that a "itemList" key was expected in trending.py

            for video in resp.get("itemList", []):
                yield Trending.parent.video(data=video)
                found += 1

I'm assuming itemList was meant to be a list of IDs as strings. However, there's nothing there, so the for loop is never run. And no video is ever returned.

weberxw commented 6 months ago

Anything on this? It still doesn't work for me

M-Minkov commented 6 months ago

Anything on this? It still doesn't work for me

Ah it's been a while, I think the creator said something on another issue tag that it requires one of the cookies for permission authentication to be set, and then it should work?

Test units will apparently not work out of the box, and must be configured.

With that being said, this probably is not a bug request. But a feature request for test units to work out of the box, or come with different errors for if the authentication cookie has not been set. So I will most likely close this bug fix request within the next 24 hours.

It's been awhile since I've looked at this though, and probably won't for awhile either. (God knows when or if TikTok introduce additional changes to combat web scrapers).