使用用户 ID (uid) 获取视频 ID (aweme_ids) 列表的确切 Tiktok API 端点是什么?

发布于 2025-01-17 01:53:30 字数 3496 浏览 2 评论 0原文

用于获取与特定用户名相对应的视频 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文