A
A
Alexander Gonchurin2015-02-05 20:48:44
Ruby on Rails
Alexander Gonchurin, 2015-02-05 20:48:44

How to download photos from instagram by hashes?

The question is, to make a normal download through the apishka from instagram is not a problem.
But how to implement this approach - the user uploads a photo with a hashtag to Instagram, and it is uploaded to the server. I understand that you need to set some kind of background task so that after a certain interval it checks for a new photo.
Please suggest or express your thoughts on how to implement this.
A little more detail if possible)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Fateev, 2015-02-05
@svfat

  1. The Instagram API has methods for working with tags, for example, you can get a list of the latest photos and videos uploaded to Instagram with the "snow" tag: https://api.instagram.com/v1/tags/snow/media/recen...
  2. After that, you pull out from the JSON response id whose created_time is greater than the last time the script was called.
  3. Upload these ids wherever you need them.
  4. Save the script call time.
  5. Push the script to cron

V
Vladimir Sobolev, 2015-06-04
@simpel

It is important to know here whether this is a new, unique tag, whether a full history of photos for this tag is needed, etc.
1. Get a list of recent photos with the desired tag and save them to the database:
2. From the answer we take pagination.next_min_idand save it for the next request.
2.a If you need a history for this tag, then make the next request using the link from pagination.next_urlor generate it yourself with an indication next_min_idfrom the paginationobject, and so on until this parameter ( next_url) is in the response or just until you get bored.
3. We request new photos indicating the parameter next_min_idand save them to the database:
4. GOTO 3.
There is a problem that I have not been able to solve yet. This algorithm works until you have a lot of photos with this tag and they all fit into one response to an API request. (parameter countcan be from 1 to 32). As soon as the number of new photos exceeds the number of new photos during the time you make a request to the API and show / save photos to the database count, you will need to download new pages next_urland with each iteration there will be more and more such pages (try the tag lovefor example).
The behavior of the tag method with a parameter next_min_idis not at all clear to me, because by specifying this parameter, count=1I expect to see exactly one photo published on Instagram immediately after the one with thisnext_min_idand was, but in fact the answer will contain the most recent photo of all that appeared in the period after next_min_idand a link to the next portion of photos from this group in next_url. How to solve this - I don't know, here is my question on SO .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question