简体   繁体   中英

Ruby: Twitter API: Get All followers

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM