2013-12-16 31 views
1

我有一種情況在我的Django項目,我需要檢索特定的Twitter用戶的所有mentions的提及。我有用戶的憑據。我已經嘗試過沒有提供足夠的搜索api,我不能提供所有的提及,並且Twitter的限制也阻礙了我所尋求的。獲得全部@user Twitter的API

所以,now I seek advice whether this can be achieved by the Streaming api or not?我還需要檢索鳴叫細節存儲在我的MongoDB數據庫,這樣我可以運行的過濾器和定製搜索。我爲此使用了twython包。

回答

0

我不知道,如果你正試圖從驗證的用戶或不能恢復,但如果你是這是我想出了。不知道這是不是最好的方式。

m = twitter.get_mentions_timeline(count=200) 
    calls = 1 
    id = m[-1]['id'] 
    next_id = -1 

    # will continue calling mentions timeline until you hit rate limit 
    # or there are no more mentions of authenticated user 
    while id != next_id and calls < 16: 
     temp = twitter.get_mentions_timeline(count=200,max_id=id) 
     calls += 1 
     next_id = temp[-1]['id'] 
     if id != next_id: 
      m += temp 
      next_id = -1 
      id = temp[-1]['id'] 

m將是所有檢索到的已認證用戶的提及數組。