使用用户 ID (uid) 获取视频 ID (aweme_ids) 列表的确切 Tiktok API 端点是什么?
用于获取与特定用户名相对应的视频 ID 的 TikTok API 列表
我一直在使用 /aweme/v1/discover/search/?keyword=USERNAME&cursor=0&count=10&type=1& 获取 USER_ID hot_search=0&search_source=发现
。因此,该端点工作正常,并成功返回用户详细信息(userId、videoCount 等)。
但是,当我尝试使用 /aweme/v1/aweme/post/user_id=USER_ID&count=20&max_cursor=CURSOR_VALUE
获取视频详细信息(videoId、描述等)时,它无法获取响应。
这是源代码的最低可重现版本:
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))
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))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论