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

BySound and ByHashtag Problem #314

Closed ziyueluo closed 4 years ago

ziyueluo commented 4 years ago

Hi, I found some problems for method bySound and byHashtag( I'm using 3.6.0) when I tried: musics=api.bySound('6883993546467051522',count=10) it returns: Traceback (most recent call last): File "", line 1, in File "D:\Anaconda3\envs\lib\site-packages\TikTokApi\tiktok.py", line 633, in bySound for t in res["body"]["itemListData"]: KeyError: 'body'

And when I tried with byHashtag, sometimes it returned the same error but sometimes it worked well. And when I used byHashtag, like: hashtags=api.byHashtag(hashtag,count=2000,proxies=proxies) the result only contained around 50 unique tiktoks and just kept repeating the same 50 tiktoks.

Thanks for your help!

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.71. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

davidteather commented 4 years ago

Are you running the latest version

ziyueluo commented 4 years ago

Yes, I'm running with version 3.6.0

davidteather commented 4 years ago

What hashtag were you trying to get

davidteather commented 4 years ago

I also can't seem to replicate your bySound issue are you sending requests too fast to TikTok?

davidteather commented 4 years ago

I'm updating the bySound endpoint and the byHashtag method although I'm not sure it will fix your issue.

ziyueluo commented 4 years ago

Right now, I tried with your latest version. BySound is working fine. But for byHashtag, I still get repeated results for some hashtags. When I run: hashtags=api.byHashtag('#HeinzHalloween',count=2000) It return 2000 results but there are only 29 unique objects.

davidteather commented 4 years ago

The hashtag string shouldn’t contain # you’re searching for ##HeinzHalloween there’s probably only 29 videos there

ziyueluo commented 4 years ago

I tried with: hashtags=api.byHashtag('HeinzHalloween',count=2000) Still the same result

davidteather commented 4 years ago
from TikTokApi import TikTokApi
api = TikTokApi()

def ensure_unique(arr):
  tmp = []
  for t in arr:
    if t['id'] not in arr:
      tmp.append(t['id'])
  return tmp

tiktoks=api.byHashtag('HeinzHalloween',count=2000)
print(len(ensure_unique(tiktoks)))

I'm personally getting 2,000 unique results.

Lancelot-d commented 3 years ago

Hi, in fact with the previous code you get 2000 unique results but if you restart the function immediately afterwards it will find the same 2000 results again. (of course the hashtag has more than 2000). how to explain this? is it resolvable?