ruby-on-rails - 试图让 Twitter 光标与 api 一起工作

标签 ruby-on-rails ruby twitter-bootstrap twitter pagination

我正在尝试使用游标方法来收集完整的用户/ friend 列表,而不是一遍又一遍地从我的用户那里收集相同的列表。请帮忙。感谢您的时间和努力:)

我的代码:

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)

最佳答案

无需直接使用光标。它是自动的。要获取用户的所有关注者,只需使用 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

关于ruby-on-rails - 试图让 Twitter 光标与 api 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29978330/

相关文章:

ruby-on-rails - 在 lib 文件夹模块中使用 url_for

ruby-on-rails - Rails 路由可在单个应用程序上处理多个域

ruby-on-rails - rails script/generate 默认跳过不必要的文件

javascript - 到达页面底部时,粘性导航栏会闪烁

html - 100% 输入宽度,可流畅拉伸(stretch)

ruby-on-rails - rails : Where to place plugin files

ruby-on-rails - 对多个模型使用一项操作

Ruby 和 nil 对象

ruby-on-rails - 如何使用 devise parent_controller 来设计继承的 Controller ,但跳过 ActiveAdmin 设计 Controller ?

javascript - Angular Bootstrap 正在创建重复的 Bootstrap 模式