davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.52k stars 928 forks source link

I got error " Failed to get msToken from cookies" #1120

Open SiwaleKamasatjakul opened 4 months ago

SiwaleKamasatjakul commented 4 months ago

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()) 
Insights0891 commented 3 months ago

Any update on this issue ?? I am facing the same @davidteather

idrinkandiknowthing commented 3 months ago

Any update? I'm facing this issue because ms_token was updated every time when browser was refreshed