2015-04-30 25 views
2

我想使用遊標方法來收集用戶/朋友的完整列表,而不是從我的用戶反覆同一個。請幫忙。感謝您的時間和精力:)試圖讓Twitter的光標與API工作

我的代碼:

cursor = -1 
followerIds = [] 
while cursor != 0 do 
followers_user = user.followers("user", {:cursor => cursor}) 

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

我的迴應:

#private method `next_cursor' called for #<Twitter::Cursor:0x007fd47482a208> (NoMethodError) 

回答

0

無需直接使用遊標。它是自動的。爲了讓所有的追隨者用戶,只需使用each

user.followers("username").each do |twitter_user| 
    # do something with twitter_user 
end 

如果你只是想的ID,使用:

user.follower_ids("username").each do |id| 
    # do something with twitter id 
end 
+0

,這不是真正的男人,你得到像280..and你會除非你知道如何使用遊標方法,否則一遍又一遍地得到相同的結果。 :\ – marriedjane875

+0

這個問題不會發生在我身上。 – infused

+0

所以當你跟twitter的API,你的用戶沒有請求超時? @infused – marriedjane875