使用Instagram gem获取所有用户的图片 [英] Fetching all user's pictures with the Instagram gem

查看:46
本文介绍了使用Instagram gem获取所有用户的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用instagram gem( https://github来获取所有图片. com/Instagram/instagram-ruby-gem ),但我无法找到方法.

I'd like to fetch all my pictures using the instagram gem (https://github.com/Instagram/instagram-ruby-gem) but I'm not able to find out how.

这是我到目前为止正在尝试的:

This is what I'm trying so far:

client = Instagram.client(access_token: token)
client.user_recent_media.each do |media|
    puts media.images.thumbnail.url
end

它显然有效(这些是我的Instagram图像),但我无法获取所有这些图像,也无法以任何方式从Instagram中选择我想要的内容.

It apparently works (those are my Instagram images) but I'm not able to fetch all of them or to select in any way which content I want from Instagram.

例如,我看到方法user_recent_media接受一个"count" 属性,该属性应允许我使用某种分页:

For example I see that the method user_recent_media accepts a "count" attribute that should let me use some sort of pagination:

(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页

Unfortunately I don't get how this paginations is supposed to work. If for example I request 1000 media elements (just to say all of them) it doesn't work and returns way less elements, at that point I'm stuck because I have no idea how to requeste page 2

有人用过Instagram的宝石吗?任何帮助将不胜感激

Has anyone used the Instagram gem for something like this? Any help is greatly appreciated

推荐答案

下面是导入用户的旧应用程序的功能代码(我刚刚使用1.1.5 Instagram Gem运行了该代码,它仍然有效),该程序还使用了光标.您应该能够更改一些变量和行并按自己的方式进行:

Below is functioning code from an old app that imports users (I just ran it with the 1.1.5 Instagram Gem and it still works), which also uses the cursor. You should be able to change a few variables and lines and be on your way:

  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

这篇关于使用Instagram gem获取所有用户的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆