TikTok-Api: [BUG] - Code doesn't return anything.
I don’t get any output from any code, even the examples provided with the package and in the readme
import logging
from TikTokApi import TikTokApi
with TikTokApi(logging_level=logging.INFO) as api:
for trending_video in api.trending.videos(count=50):
print(trending_video.author.username)
I’ve tried reinstalling it, installing it from outside the venv, reinstalling playwright, passing the cookie to the API and nothing changed. Is anyone else having the same issue?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 28 (1 by maintainers)
I was having this issue, but I noticed the url generated worked fine in my browser
So I exported the cookies from my browser (I’m logged into TikTok) into
cookies.jsonand then was able to use the below to set those cookies in all requests through the apiThis is working for me
Here’s the step-by-step that worked for me, @Wathfea:
@Wathfea - I’m using “edit this cookie” chrome plugin to do the export of cookies
My exported file looks like this:
Although the only thing we need is the
nameandvaluefields, as long as those are populated the code will work And in my code you can see I actually had to format it to be a more simple format before passing it through, so eventually you just have@dhudsmith or @adamd01 can you please describe step by step what did you do? I tried to recreate what you sad but I’m out of luck.
I saved the cookie.json in the above format what you wrote and chaged the code for the correct key value pairs bt the script still idle and I can’t get back any response.
Here is my code:
UPDATE: I was able to get @adam01’s solution to work. I was able to get the cookies.json in the correct form by using Chrome along with the Cookie Editor extension (https://add0n.com/cookie-editor.html)
@adamd01, thanks for sharing this. ~I can’t get it to work.~ Can you give a little more detail about which cookies file you saved? I’m seeing 33 cookies for the tiktok domain. I exported all of these as a cookies.json. I get an array of the following objects. Where are the “key” and “value” coming from in your snippet.
FYI, I’m on firefox and I am using the “Quick Cookie Manager” to export the json.
api.user is also working when you pass the output of trending_video.author to user as follows:
This works!!
api.trending – works only api.user – not working api.sound – not working