加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ruby:Twitter API:获取所有关注者

发布时间:2020-12-17 02:51:42 所属栏目:百科 来源:网络整理
导读:任何人都知道为什么下面的代码中的下一个光标没有改变? 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"
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.

解决方法

编辑:[关于限速率删除的建议]

问题是follow_ids的游标选项.它应该是:

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

注意使用符号,而不是字符串.在原始代码中,提供的“cursor”选项被忽略,follower_ids正在执行默认行为,即返回关注者的第一页.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读