#1120·TikTok-Api

I got error " Failed to get msToken from cookies"

Author: SiwaleKamasatjakulCreated Mar 1, 2024Updated Mar 22, 2026
Labelsbug

I got mstoken from inspect and after I ran terminal I got this error

024-03-01 21:11:59,929 - TikTokApi.tiktok - WARNING - Failed to get msToken from cookies, trying to make the request anyway (probably will fail) 2024-03-01 21:12:01,302 - TikTokApi.tiktok - ERROR - Got an unexpected status code: {'userInfo': {'user': {}, 'stats': {}, 'shareMeta': {}}}

This is the code I use from repo

from TikTokApi import TikTokApi
import asyncio
import os
ms_token = os.environ.get(
    "mstoken", None  # I change to my mstoken already
)  
async def user_example():
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
        user = api.user("therock")
        user_data = await user.info()
        print(user_data)

        async for video in user.videos(count=30):
            print(video)
            print(video.as_dict)
if __name__ == "__main__":
    asyncio.run(user_example())