Tweepy Twitter获得特定用户的所有推文回复 [英] Tweepy Twitter get all tweet replies of particular user
问题描述
我正在尝试获取此特定用户的所有回复.因此该特定用户的reply_to_user_id_str为151791801.我尝试打印所有答复,但不确定如何发送.但是,我只能打印出其中的1条回复.有人可以帮我打印所有答复吗?
I am trying to get all replies of this particular user. So this particular user have reply_to_user_id_str of 151791801. I tried to print out all the replies but I'm not sure how. However, I only manage to print out only 1 of the replies. Can anyone help me how to print out all the replies?
我的代码是:
for page in tweepy.Cursor(api.user_timeline, id="253346744").pages(1):
for item in page:
if item.in_reply_to_user_id_str == "151791801":
print item.text
a = api.get_status(item.in_reply_to_status_id_str)
print a.text
推荐答案
首先,找到与服务提供商进行对话的转发线程:
First, find the retweet thread of your conversation with your service provider:
# Find the last tweet
for page in tweepy.Cursor(api.user_timeline, id="253346744").pages(1):
for item in page:
if item.in_reply_to_user_id_str == "151791801":
last_tweet = item
变量最新推文
将包含您的最新转发.从那里,您可以循环回到原始推文:
The variable last tweet
will contain their last retweet to you. From there, you can loop back to your original tweet:
# Loop until the original tweet
while True:
print(last_tweet.text)
prev_tweet = api.get_status(last_tweet.in_reply_to_status_id_str)
last_tweet = prev_tweet
if not last_tweet.in_reply_to_status_id_str:
break
虽然不漂亮,但可以完成工作.祝你好运!
It's not pretty, but it gets the job done. Good luck!
这篇关于Tweepy Twitter获得特定用户的所有推文回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!