我想使用 Instagram gem 获取我的所有照片(https://github.com/Instagram/instagram-ruby-gem https://github.com/Instagram/instagram-ruby-gem)但我不知道怎么做。
到目前为止,这就是我正在尝试的:
client = Instagram.client(access_token: token)
client.user_recent_media.each do |media|
puts media.images.thumbnail.url
end
它显然有效(这些是我的 Instagram 图片),但我无法获取他们全部或以任何方式选择我想要从 Instagram 获取哪些内容。
例如,我看到方法 user_recent_media 接受"count"属性应该让我使用某种分页:
(from https://github.com/Instagram/instagram-ruby-gem/blob/master/lib/instagram/client/users.rb#L150)
@option options [Integer] :count (nil) Limits the number of results returned per page
不幸的是我不明白这个分页应该如何工作。例如,如果我请求 1000 个媒体元素(只是说全部),它不起作用并且返回的元素少得多,此时我陷入困境,因为我不知道如何请求第 2 页
有人用 Instagram gem 做过类似的事情吗?任何帮助是极大的赞赏
下面是一个导入用户的旧应用程序的功能代码(我刚刚使用 1.1.5 Instagram Gem 运行它,它仍然有效),它也使用光标。您应该能够更改一些变量和行并继续前进:
def import_followers
response = user.client.user_follows
followers = [].concat(response)
next_cursor = response.pagination[:next_cursor]
while !(next_cursor.to_s.empty?) do
response = Instagram.user_follows(uid, {:cursor => next_cursor})
next_cursor = response.pagination[:next_cursor]
followers.concat(response)
end
return followers
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)