LoginSignup
2
2

More than 5 years have passed since last update.

instagram-ruby-gemの形式でnext_urlを扱う方法

Last updated at Posted at 2015-11-25

2015/11/25の時点で、instagram-ruby-gemnext_urlを使ったデータの取得をサポートしていません。
そのため、この記事ではgemで取得したデータと同じ形式でnext_urlのデータを扱う方法を共有します。
なぜなら、それができるとviewを使いまわせて便利だからです。

実現方法

Hashie::MashInstagram::Responseを使います。
この例ではtag_recent_mediaで取得したnext_urlから、次のデータを取得しています。

medias = Instagram.tag_recent_media('タグの名前')
next_url = medias.pagination.next_url

if next_url
  response = Faraday.get(next_url)
  response_hash = JSON.parse(response.body)
  response_hashie = Hashie::Mash.new(response_hash)
  next_url_medias = Instagram::Response.create(response_hashie, {})
end

上記の内容を実現するpull requestを申請中です。
賛同頂ける方は+1のコメントをしていただけると、pull requestが受理してもらいやすくなるかもしれません。
https://github.com/Instagram/instagram-ruby-gem/pull/194

もっと良さそうなデータの扱い方があれば、教えて頂けると嬉しいです。

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2