TikTok does provide some endpoints for developers, but since TikTok is primarily a mobile app, the web support feels secondary. Personally, I find the web endpoints provided by TikTok to be quite basic compared to their mobile app offerings.
For more details, you can check out their developer site: https://developers.tiktok.com/
It seems like the API offerings for developers in their home country are more extensive, but the international API doesn't seem to get as much attention.
Below is a simple example using the oEmbed feature:
Example:
https://www.tiktok.com/oembed?url=https://www.tiktok.com/@scout2015/video/6718335390845095173
Response:
json
Copy
{
"version": "1.0",
"type": "video",
"title": "Scramble up ur name & Iβll try to guess itπβ€οΈ #foryoupage #petsoftiktok #aesthetic",
"author_url": "https://www.tiktok.com/@scout2015",
"author_name": "Scout & Suki",
"width": "100%",
"height": "100%",
"html": "<blockquote class=\"tiktok-embed\" cite=\"https://www.tiktok.com/@scout2015/video/6718335390845095173\" data-video-id=\"6718335390845095173\" style=\"max-width: 605px;min-width: 325px;\" > <section> <a target=\"_blank\" title=\"@scout2015\" href=\"https://www.tiktok.com/@scout2015\">@scout2015</a> <p>Scramble up ur name & Iβll try to guess itπβ€οΈ <a title=\"foryoupage\" target=\"_blank\" href=\"https://www.tiktok.com/tag/foryoupage\">#foryoupage</a> <a title=\"petsoftiktok\" target=\"_blank\" href=\"https://www.tiktok.com/tag/petsoftiktok\">#petsoftiktok</a> <a title=\"aesthetic\" target=\"_blank\" href=\"https://www.tiktok.com/tag/aesthetic\">#aesthetic</a></p> <a target=\"_blank\" title=\"β¬ original sound - πππ°ππ’π’π\" href=\"https://www.tiktok.com/music/original-sound-6689804660171082501\">β¬ original sound - πππ°ππ’π’π</a> </section> </blockquote> <script async src=\"https://www.tiktok.com/embed.js\"></script>",
"thumbnail_width": 720,
"thumbnail_height": 1280,
"thumbnail_url": "https://p16.muscdn.com/obj/tos-maliva-p-0068/06kv6rfcesljdjr45ukb0000d844090v0200010605",
"provider_url": "https://www.tiktok.com",
"provider_name": "TikTok"
}
The Request URL contains the username (@scout2015), but this is optional. It seems like only the video_id is actually checked.
If you hit a malformed Request URL, you'll get a simple prototype-like message that doesn't even explain the error:
json
Copy
{
"status_msg": "Something went wrong"
}
The developer page contains a few more features, but the documentation for mobile is also quite basic.
So, let's introduce an easy-to-use unofficial API library for TikTok.
Unofficial TikTok API in Python: https://github.com/davidteather/TikTok-Api
Documentation: https://dteather.com/TikTok-Api/docs/TikTokApi.html
Step 1: Install the package
sh
Copy
$ pip install TikTokApi
$ python -m playwright install
Step 2: Obtain custom_verifyFp
Since this is unofficial, there are no tokens, so this step is necessary. Access TikTok, go to Dev Tools > Application > Storage > Cookies, and copy s_v_web_id to use as verifyFp in the sample code below.
There's alsoa video by the author of the library:
https://youtu.be/zwLmLfVI-VQ?t=121
In this post, we will use the by_hashtag method to retrieve 10 posts tagged with "Messi." You can find the documentation for by_hashtag here:
https://dteather.com/TikTok-Api/docs/TikTokApi/tiktok.html#TikTokApi.by_hashtag
The YouTube video above uses the by_trending method:
https://dteather.com/TikTok-Api/docs/TikTokApi/tiktok.html#TikTokApi.by_trending
The code itself is very simple. It fetches 10 video links tagged with "Messi." Note that the maximum you can fetch is 2000.
If you want to know the JSON data format returned, check this out:
https://gist.github.com/koji/143ea8387403899c069464cbde61efae
Here is the test.py:
python
Copy
from TikTokApi import TikTokApi
verifyFp = 'xxx'
api = TikTokApi.get_instance(custom_verifyFp=verifyFp, use_test_endpoints=True)
results = 10
hashtag = 'Messi'
search_results = api.by_hashtag(count=results, hashtag=hashtag)
for tiktok in search_results:
print(tiktok['video']['playAddr'])
Step 3: Run the code
Run the above code, and you will get the results:
sh
Copy
$ python test.py
$ python test.py
https://v16-web.tiktok.com/video/tos/useast2a/tos-useast2a-pve-0068/f6d3605bceb3438d95d3fc15e1c12707/?a=1988&br=3614&bt=1807&cd=0|0|1&ch=0&cr=0&cs=0&cv=1&dr=0&ds=3&er=&expire=1628935350&ft=Q9BExEXk_4ka&l=202108140401520102450730214E194969&lr=tiktok_m&mime_type=video_mp4&net=0&pl=0&policy=3&qs=0&rc=M2k0ZmY1cGp0MzMzOTczM0ApaDY3Ojw0ODw4N2RoZmkzO2dhbW0xYzFjZG1gLS00MTZzczAxL2AyNDAyMzAuLy8zXzM6Yw%3D%3D&signature=5deb49d12d31945a3dd829845980247c&tk=0&vl=&vr=
Looking at the issues in the repository, it seems that when TikTok is updated, the results might not be returned correctly. So, while this is good for creating simple tools for web or desktop, it might not be suitable for building typical applications that rely on standard APIs.
You can download Tiktok videos with Snaptik or Snaptiktok quickly
https://snaptiktok.info/