2010-12-22 68 views
4

任何人都知道爲什麼下面的遊標在下面的代碼中沒有改變?Ruby:Twitter API:獲取所有關注者

cursor = "-1" 
followerIds = [] 
while cursor != 0 do 
followers = Twitter.follower_ids("IDTOLOOKUP",{"cursor"=>cursor}) 

cursor = followers.next_cursor 
followerIds+= followers.ids 
sleep(2) 
end 

在cursor = -1的第一次迭代之後,它會從twitter api分配nextcursor。然而,當它在後續迭代中發送到Twitter API時,我得到的迴應與我第一次相同 - 使用相同的next_cursor。

任何想法我做錯了什麼?我正在使用twitter gem。

回答

8

編輯:[關於存在速率受限的建議除去]

問題是光標選項follow_ids。它應爲:

followers = Twitter.follower_ids("IDTOLOOKUP",{:cursor=>cursor}) 

請注意使用符號而不是字符串。在原始代碼中,提供的「遊標」選項被忽略,follower_ids正在執行默認行爲,即返回關注者的第一頁。

+0

認爲最初也是如此。但不是。剩下很多。 – RekrowYnapmoc 2010-12-22 02:32:58

相關問題