Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram gem: getting photos with specific hashtags

Is it possible to select only pictures with certain hashtags from a user using the instagram gem? Couldn't find hashtag select in the docs. If so, please provide an example.

like image 827
bevanb Avatar asked Feb 21 '23 09:02

bevanb


1 Answers

It can't be done directly. The Instagram API itself doesn't let you make a call like this- you have to either query a particular user's photos, or query a tag, and the gem provides no workaround.

So, first query the user:

  @results = Instagram.user_recent_media(1907035, {access_token: t.token, count: 60})  # 60 appears to be the max

Then keep the photos with the tags you want. In the results, each element has a "tags" array. For example @results.first["tags"] returns the array of tags for the first photo.

Here's the well-documented code for making typical queries:

https://github.com/Instagram/instagram-ruby-gem/blob/master/lib/instagram/client/users.rb

like image 182
bevanb Avatar answered Mar 05 '23 05:03

bevanb