TikTok-Api icon indicating copy to clipboard operation
TikTok-Api copied to clipboard

[FEATURE_REQUEST] - Is there any way to get likes count for each video

Open gridikono opened this issue 1 year ago • 3 comments

Is there any way to get likes count for each video?

gridikono avatar Nov 07 '23 17:11 gridikono

hey @gridikono We can already do that, I wrote this little function so you should be able to do so

def tiktokUrlBuilder(username, videoID):
    return f"https://www.tiktok.com/@{username}/video/{videoID}"

async def getUserVideos(username):
    videos = []
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, headless=False, override_browser_args=["--incognito"])
        user = api.user(username)
        # user_data = await user.info()
        async for video in user.videos(count=10):
            videos.append(video.as_dict)
    return videos

async def getVideoInfo(username, video):
    videoUrl = tiktokUrlBuilder(username, video['id'])
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
        video_object = api.video(url=videoUrl)
        videoInfo = await video_object.info()
        return videoInfo

shinitiandrei avatar Nov 09 '23 11:11 shinitiandrei

Hi @shinitiandrei,

Thanks for posting the code, just wondering how you found out to write "headless=False", it looks like making headless=True currently causes an error, I'm not too sure how come though?

This can be seen from the PyTest modules underneath the tests\ directory (about half of them are currently failing straight out of the box)

M-Minkov avatar Nov 10 '23 09:11 M-Minkov

Hi @shinitiandrei,

Thanks for posting the code, just wondering how you found out to write "headless=False", it looks like making headless=True currently causes an error, I'm not too sure how come though?

This can be seen from the PyTest modules underneath the tests\ directory (about half of them are currently failing straight out of the box)

Hey @M-Minkov Follow this thread, I've posted my answer that at the bottom how I found the fix: https://github.com/davidteather/TikTok-Api/issues/1074

shinitiandrei avatar Nov 10 '23 13:11 shinitiandrei