2015-07-19 46 views
5

我正在嘗試獲取此特定用戶的所有回覆。所以這個特定用戶的reply_to_user_id_str爲151791801.我試圖打印出所有的回覆,但我不知道如何。但是,我只能打印出只有一個答覆。任何人都可以幫助我如何打印出所有的答覆? enter image description hereTweepy Twitter獲取特定用戶的所有鳴叫回復

我的代碼是:

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 

Output:

回答

7

首先,找到你的談話的轉推螺紋與服務提供商:

# 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 

變量last 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 

它不漂亮,但它能夠完成任務。 祝你好運!

+0

謝謝!有用。只有一個問題,你知道你如何避免鳴叫限制?嘗試過的例外,但does not無效 –

+0

你的意思是twitter API的速率限制?您可以在設置api時將wait_on_rate_limit參數設置爲true。例如:'api = tweepy.API(auth_args,wait_on_rate_limit = True)'。 – jjinking

+0

這是否回答你的問題? – jjinking