开发者

Ruby: Twitter API: Get All followers

开发者 https://www.devze.com 2023-02-01 04:54 出处:网络
Anyone have any idea why the next cursor isn\'t changing in the below code? cursor = \"-1\" followerIds = []

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

cursor = "-1"
followerIds = []
whi开发者_JAVA百科le 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消