[英]Tweepy Get Tweets in reply to a particular tweet
因此,我已經在Tweepy和Twitter數據挖掘方面做了很多工作,而我想做的一件事情就是能夠獲取所有對特定Tweet的回復的Tweet。 我已經看過Search api,但是我不確定如何使用它,也不確定如何專門搜索Tweets以回復特定的Tweet。 有人有想法么? 謝謝大家
我已經創建了一種解決方法。 最好的方法是搜索用戶的提及,然后通過in_reply_to_id過濾這些提及。
user_name = "@nameofuser"
replies = tweepy.Cursor(api.search, q='to:{}'.format(user_name),
since_id=tweet_id, tweet_mode='extended').items()
while True:
try:
reply = replies.next()
if not hasattr(reply, 'in_reply_to_status_id_str'):
continue
if str(reply.in_reply_to_status_id) == tweet_id:
logging.info("reply of tweet:{}".format(reply.text))
except tweepy.RateLimitError as e:
logging.error("Twitter api rate limit reached".format(e))
time.sleep(60)
continue
except tweepy.TweepError as e:
logging.error("Tweepy error occured:{}".format(e))
break
except StopIteration:
break
except Exception as e:
logger.error("Failed while fetching replies {}".format(e))
break
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.