Darshan Mehta
Darshan Mehta

Reputation: 30809

Instagram API Pagination : Next page

I am trying to get all the recent media by tag using this Instagram endpoint. The purpose here is to track all the recent media for tags. I have configured a scheduled task (with Java and Spring) (to execute every hour) that sends requests and gets data. Below is the execution sequence:

Once the execution finishes, next execution (after let's say an hour) will start with previously stored max_tag_id.

The issue I am seeing is, I never get 'recent' documents in subsequent executions. As per the documentation, passing max_tag_id in the request should return all the media after that id, however it's not happening. I keep getting old media.

If I want to get the recent documents in every execution, do I need to pass null max_id in the first request of every execution? If I do that, will I not get redundant documents in every execution? I tried asking Instagram but haven't got any response. Also, their documentation explains little about pagination. Not sure whether pagination for recent media endpoint works backwards.

Upvotes: 1

Views: 1214

Answers (1)

krisrak
krisrak

Reputation: 12952

If you want most recent don't use max_tag_id, If you use max_tag_id it will return all media dated before that.

You need to get the min_tag_id and store it, in the next hour start by making call with only min_tag_id, if there is pagination.next_url, use that to get next set of 20, until pagination.next_url does not exist.... use the stored min_tag_id to make calls the next hour.

The very first time you make call without max_tag_id or min_tag_id

You can also set the &count=32, to get 32 posts with every API call, (32 is max from my experience)

Upvotes: 1

Related Questions