Get Comments onto a specific Thread

30 views Asked by At

i‘m totally new to python and tweepy. All i want to do is get all comments to a specific thread and save them in a txt. Really, i thought this couldn‘t be this hard, but i don‘t get it. I get the error:


Traceback (most recent call last):
  File "iCloud Drive/Ohne Titel.py", line 9, in
 <module>
    conversation = client.conversation(conversa
tion_id)
AttributeError: 'Client' object has no attribut
e 'conversation'

The code:

import tweepy

BEARER_TOKEN = ' TOKEN '

client = tweepy.Client(BEARER_TOKEN)

# Get the conversation
conversation_id = " ID "
conversation = client.conversation(conversation_id)

# Save conversation to a text file
with open("conversation_{}.txt".format(conversation_id), "w") as f:
    for tweet in conversation:
        f.write(f"{tweet.author.name}: {tweet.text}\n\n")

print("Conversation saved to conversation_{}.txt".format(conversation_id))

Who can help me? Thanks in advance!

1

There are 1 answers

0
thetaco On

I do not see a client.conversation option in the Tweepy documentation. Did you by chance mean client.dm_conversations ?