Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - async for reply in comment.replies(count=10): replies It is always impossible to get the comment data of the reply #1181

Open
renzaijianghu1 opened this issue Aug 11, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@renzaijianghu1
Copy link

from TikTokApi import TikTokApi
import asyncio
import os

video_id = 7379950165601307905
ms_token = os.environ.get("ms_token", None) # set your own ms_token

async def get_comments():
async with TikTokApi() as api:
await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
video = api.video(id=video_id)
api.trending
count = 0

    # Get comments
    async for comment in video.comments(count=400):
        count += 1
        if comment.as_dict['reply_comment_total'] > 0:
            print('count:', count)
            try:
                async for reply in comment.replies(count=10):
                    print("reply:", reply)
                    print("***1:", reply.id)
                    print("***2:", reply.parent)
                    print("***3::", reply.as_dict)
                    print("***4::", reply.likes_count)
                    print("***5::", reply.author)
                    print("***6::", reply.text)

            except Exception as e:
                print("Error retrieving replies:", e)

if name == "main":
asyncio.run(get_comments())

@renzaijianghu1 renzaijianghu1 added the bug Something isn't working label Aug 11, 2024
@Giaochan
Copy link

Any news on this?
No replies object is found in the comments object, this is the code im using
from TikTokApi import TikTokApi
import asyncio
import os

video_id = 7248300636498890011
ms_token = os.environ.get("ms_token", None) # set your own ms_token

async def get_comments():
async with TikTokApi() as api:
await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
video = api.video(id=video_id)
count = 0

    async for comment in video.comments(count=30):
        print("Comment:")
        print(comment)
        print(comment.as_dict)

        # Fetch and print replies for the comment
        async for reply in comment.replies(count=10):  # Adjust count as needed
            print("  Reply:")
            print(reply)
            print(reply.as_dict)

if name == "main":
asyncio.run(get_comments())

@Giaochan
Copy link

any news?

@ocofon
Copy link

ocofon commented Oct 13, 2024

One parameter to retrieve the replies is wrong.

"item_id": self.author.user_id,

item_id should be the video id and not the user id.

"item_id": self.as_dict["aweme_id"],

You can workaroud this by adding comment.author.user_id = comment.as_dict["aweme_id"] right before the comment.replies() call.

e.g.:

        comment.author.user_id = comment.as_dict["aweme_id"]
        async for reply in comment.replies(count=10):
            print("  Reply:")
            print(reply)
            print(reply.as_dict)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants