'What is the exact Tiktok API endpoint to get list of video ids (aweme_ids) using user id (uid)?
TikTok API to fetch the list of video ids corresponding to a particular username
I have been getting the USER_ID using /aweme/v1/discover/search/?keyword=USERNAME&cursor=0&count=10&type=1&hot_search=0&search_source=discover
. So, this endpoint is working fine, and returning the user details (userId, videoCount, etc.) successfully.
But when I tried to fetch the video details (videoId, description, etc.) using /aweme/v1/aweme/post/user_id=USER_ID&count=20&max_cursor=CURSOR_VALUE
, then it's unable to fetch the response.
Here's the minimum reproducible version of the source code:
import requests
def awemeRequest(request_path, type="get"):
headers = {
"User-Agent": "okhttp",
}
url = "https://api-t2.tiktokv.com" \
+ request_path \
+ "&device_id=6158568364873266588" \
+ "&version_code=100303" \
+ "&build_number=10.3.3" \
+ "&version_name=10.3.3" \
+ "&aid=1233" \
+ "&app_name=musical_ly" \
+ "&app_language=en" \
+ "&channel=googleplay" \
+ "&device_platform=android" \
+ "&device_brand=Google" \
+ "&device_type=Pixel" \
+ "&os_version=9.0.0"
if type == "get":
resp = requests.get(url, headers=headers)
if type == "post":
resp = requests.post(url, headers=headers)
return resp
def getUidByUsername(username):
endpoint = "/aweme/v1/discover/search/" \
+ "?keyword=" + username \
+ "&cursor=0" \
+ "&count=10" \
+ "&type=1" \
+ "&hot_search=0" \
+ "&search_source=discover"
response = awemeRequest(endpoint, type="post").json()
for userObj in response.get("user_list"):
userInfo = userObj.get("user_info")
if userInfo.get("unique_id") == username:
userId = userInfo.get('uid')
videoCount = userInfo.get('aweme_count')
roomId = userInfo.get('room_id')
secUid = userInfo.get('sec_uid')
return userId
return ""
def getVideosIdByUid(uid, cursor=0, hasmore=True, page=1, count=0, total=0):
endpoint = "/aweme/v1/aweme/post/?" \
+ "user_id=" + str(uid) \
+ "&count=20" \
+ "&max_cursor=" + str(cursor)
response = awemeRequest(endpoint, type="get")
print(response.content)
hasmore = response.get('has_more', True)
cursor = response.get("max_cursor", cursor)
videosIdList = []
for videoObj in response.get("aweme_list"):
awemeId = videoObj.get("aweme_id")
url = videoObj.get("video").get("play_addr").get('url_list')[0]
createTime = videoObj.get("create_time")
description = videoObj.get("desc")
userName = videoObj.get("author").get('unique_id')
count += 1
videosIdList.append(awemeId)
if hasmore:
print()
page += 1
getVideosIdByUid(uid=uid, cursor=cursor, hasmore=hasmore,
page=page, count=count, total=total)
else:
print()
print("> Finished adding ({:d}/{:d}) videos.".format(count, total))
if count < total:
print("! {:d} videos are missing, they are either private or have\n! otherwise not been returned by TikTok's API for unknown reasons.".format((total-count)))
return videosIdList
userId = getUidByUsername('washingtonpost')
print(userId)
print(getVideosIdByUid(userId))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|