如何使用tweepy和python获取给定推文的回复?
经过一番搜索,我找到了一种方法来下载某个用户最近的推文。现在我想获得每条推文的回复。我知道twitterapi不提供端点来获取tweet的回复,除非我们有一个高级帐户。但我可以在网上找到一些解决办法。我找到了一种方法,可以用它来获取一些推特和他们的回复。下面也给出了该代码 如何修改代码(getData.py)以将每条tweet的回复与tweet一起保存在csv中? 我的代码下载用户的tweets作为csv(getData.py) 如何获得给定推文的回复 这段代码将获取一个用户(姓名)最近的10条tweet以及对该特定tweet的回复如何使用tweepy和python获取给定推文的回复?,python,tweepy,Python,Tweepy,经过一番搜索,我找到了一种方法来下载某个用户最近的推文。现在我想获得每条推文的回复。我知道twitterapi不提供端点来获取tweet的回复,除非我们有一个高级帐户。但我可以在网上找到一些解决办法。我找到了一种方法,可以用它来获取一些推特和他们的回复。下面也给出了该代码 如何修改代码(getData.py)以将每条tweet的回复与tweet一起保存在csv中? 我的代码下载用户的tweets作为csv(getData.py) 如何获得给定推文的回复 这段代码将获取一个用户(姓名)最近的10条
replies=[]
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
for full_tweets in tweepy.Cursor(api.user_timeline,screen_name='tartecosmetics',timeout=999999).items(10):
for tweet in tweepy.Cursor(api.search,q='to:'+'tartecosmetics',result_type='recent',timeout=999999).items(1000):
if hasattr(tweet, 'in_reply_to_status_id_str'):
if (tweet.in_reply_to_status_id_str==full_tweets.id_str):
replies.append(tweet.text)
print("Tweet :",full_tweets.text.translate(non_bmp_map))
for elements in replies:
print("Replies :",elements)
replies.clear()
replies=[]
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
for full_tweets in tweepy.Cursor(api.user_timeline,screen_name='tartecosmetics',timeout=999999).items(10):
for tweet in tweepy.Cursor(api.search,q='to:'+'tartecosmetics',result_type='recent',timeout=999999).items(1000):
if hasattr(tweet, 'in_reply_to_status_id_str'):
if (tweet.in_reply_to_status_id_str==full_tweets.id_str):
replies.append(tweet.text)
print("Tweet :",full_tweets.text.translate(non_bmp_map))
for elements in replies:
print("Replies :",elements)
replies.clear()
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 reply.in_reply_to_status_id == tweet_id:
logging.info("reply of tweet:{}".format(reply.full_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