Russell-Newton / TikTokPy

Extract data from TikTok without needing any login information or API keys.
https://pypi.org/project/tiktokapipy/
MIT License
214 stars 28 forks source link

[QUESTION] How to retrieve more than 30 videos from a user #37

Closed emacollins closed 1 year ago

emacollins commented 1 year ago

Ask your question I am pulling video data by passing through a username. The data that returns is what I want, however it only retrieves the user's 30 most recent videos. I see there is a video_limit parameter, but this seems to be invoked after the response is returned. I tried setting scrolling_down_time higher, but no matter how high, it still returns only 30 videos. The data response gets saved to a json how I want it to, so the only issue is this 30 video limit. Any help would be appreciated, thanks!

Here is my function

def get_user_video_data(username: str) -> None:

    filepath = 'some/file/path'
    with TikTokAPI(scroll_down_time=100,navigation_retries=5, navigation_timeout=0, 
                   data_dump_file=filepath) as api:
        user = api.user(username)
Russell-Newton commented 1 year ago

Are you saying that there's only 30 videos in the data dump file? This is due to the nature of how TikTokPy retrieves videos. The first thing it does is grab the preloaded data that TikTok receives from its own API when you load a page. This is the data that gets dumped into the data dump file. If there's a scroll down time, TikTokPy will start scrolling down and capture the result of any API calls TikTok makes to retrieve more videos, comments, etc. Any of this extra data is saved under the "extras" field in the dumped JSON.

If you want to have access to the Video objects that are loaded on a user page, you can make use of the videos iterator from the loaded User

emacollins commented 1 year ago

Yes, only 30 videos in the data dump. Ideally I would want all videos from a user in the data dump file. The extras field in the data dump file seems to always be an empty list, even when setting a high scroll time. Will using the video iterator give me a way to get all of the videos then?

emacollins commented 1 year ago

It seems that iterating over the video objects still limits the results to 30 videos @Russell-Newton

Russell-Newton commented 1 year ago

The video iterator stops after the video limit is reached. This defaults to 25. Setting it to 0 will remove the limit. If it still only gets a handful of videos, it's possible then that something is keeping TikTok from retrieving more API data. If setting the video limit to 0 doesn't work, what version of TikTokPy are you using?

emacollins commented 1 year ago

Hmm okay, I set the limit to 0 with no luck. I am using version 0.1.9.post1

Russell-Newton commented 1 year ago

That'll do it. This was an issue that I fixed in 0.1.10.post1 if I remember correctly. I'd recommend updating to the latest version (0.1.11) and trying again.

emacollins commented 1 year ago

Awesome, I just updated and it seems my data dump files are much larger, so it seems to be capturing the extra data. Thank you so much!

erdinhrmwn commented 1 year ago

I'm using latest version but still get max 30 most recent videos even set video_limit to 0. Any clue for this?