A simple Python wrapper for querying video & user data with TikTok's Research API.
To use this code, you must first apply for and receive access to the Research API.
This repo is a fork of the code provided by adinagit.
For more general info, consult TikTok's Research API Reference for querying videos.
Use the script TT_extractor.py
For the script to run, you must insert your CLIENT KEY and CLIENT SECRET in a .env file and then pass that path in the folder.py file in /config_files This way you can work on git without having to write in clear your keys.
The script takes the following arguments:
- Begin Year -> First year of the extraction
- Finish Year -> Last year of the extraction
- num-queries -> How many queries to perform by month
- RANDOM? -> Use this if you want to have random results returned, currently only function implemented
- day -> date of the collection, useful for creating folders
- Access tokens are good for 2 hours, but the script is set up to generate a new one every hour.
I want to gather 1000 videos a day for all the months from 2020 to 2023
python TT_extractor.py -by 2020 -fy 2023 -n 10 -rnd -day $(date +%Y-%m-%d) <- this last piece will give you the current date, you can also set this up in a crontab job ( n=10 since it will do 10 queries of 100 elements)
The original scripts by adinagit are stored in /base_code. For documentation about those, you should refer to the original repo.