Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: Twitter API: Get All followers

Tags:

ruby

twitter

Anyone have any idea why the next cursor isn't changing in the below code?

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

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

After the first iteration where cursor = -1, it gets assigned the nextcursor from the twitter api. However, when this is sent to the twitter API on subsequent iterations, I get the same response back as I did the first time.. with the same next_cursor.

Any ideas what I'm doing wrong? I'm using the twitter gem.

like image 985
RekrowYnapmoc Avatar asked Feb 25 '23 13:02

RekrowYnapmoc


1 Answers

Edit: [Suggestion regarding being rate limited removed]

The problem is the cursor option to follow_ids. It should read:

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

Note the use of symbol, not string. In the original code, the "cursor" option being provided was being ignored and follower_ids was doing the default behavior, namely returning the first page of followers.

like image 104
Steve Wilhelm Avatar answered Mar 07 '23 00:03

Steve Wilhelm