davidteather / TikTok-Api

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

KeyError: 'hasMore' #681

Closed surenjanath closed 3 years ago

surenjanath commented 3 years ago

Describe the bug

from TikTokApi import TikTokApi

api = TikTokApi.get_instance()
device_id = api.generate_device_id()
tiktoks = api.by_sound('6966808242676599558', count=10,custom_device_id=device_id)

Expected behavior It was working a couple hours ago and now .. it's not

Error Trace (if any)

File "/usr/local/lib/python3.7/dist-packages/TikTokApi/tiktok.py", line 858, in by_sound
    if not res["hasMore"]:
KeyError: 'hasMore'

Ok only this giving hasMore error. the method by_trending works ... okay by_trending only returning 5 videos alone

weavewillG commented 3 years ago

I'm facing the same issue.

weavewillG commented 3 years ago

looks like the /api/music/item_list endpoint now requires msToken. @davidteather any idea how to generate that token?

surenjanath commented 3 years ago

i ssee u trying something .. the mstoken is same as the xmst. it's stored in local storage

surenjanath commented 3 years ago

okay so what i've found is if u make normal request using

header = {
'authority': 'm.tiktok.com',
'method': 'GET',
'scheme': 'https',
'accept': '*/*',
'accept-encoding': 'gzip, deflate, br',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36',
'x-tt-params' <MUST INCLUDE THIS>: 
}

url = 'https://m.tiktok.com/api/music/item_list/?msToken=....&X-Bogus=....&_signature=....'
r = requests.get(url, headers= header, allow_redirects= True)
r.json()

it works.. it must have the x-tt-params though.. they seemed to convert the musicID and count everything into a hash code :/

martmalo commented 3 years ago

when this will be fixed?

alma359 commented 3 years ago

I have the same problem now.

davidteather commented 3 years ago

Consolidating all discussion about x-tt-params, user_posts, and anything else related to this update to #695 for easier collaboration