Home » Swift » Instagram /tags/\(hashtag)/media/recent endpoint not returning pagination?

Instagram /tags/\(hashtag)/media/recent endpoint not returning pagination?

Posted by: admin November 30, 2017 Leave a comment


I’ve been trying to get this to work for probably 6 hours now to no avail, read every stackoverflow question I could find on the topic.

I’m trying to get 100, 200, or maybe 500 photos from a single tag:

func hashtags(hashtag: String, nextMaxTagId: String?) -> RequestParamters {
    var params = "/tags/\(hashtag)/media/recent|access_token=\(accessToken)"
    var parameters = Dictionary<String, AnyObject>()
    parameters["access_token"] = accessToken

    let urlString = "https://api.instagram.com/v1/tags/\(hashtag)/media/recent"
    if let nextMaxTagId = nextMaxTagId {
        params += "|max_tag_id=\(nextMaxTagId)"
        parameters["max_tag_id"] = nextMaxTagId

    let sig = HMAC.signWithKey(C.InstagramClientSecret(), usingData: params)
    parameters["sig"] = sig
    return (urlString: urlString, parameters: parameters)

This is what I use to construct my urls and parameters for my request. My first request does not have a nextMaxTagId, and that request goes through, returns 20 images and a pagination json.

Then, when I extract the next_max_tag_id from the pagination block, and create a request using that parameter, I get another 20 images, but they are the same images as before and now I do not get a pagination block.

I am signing my requests correctly (as all my other API requests throughout the app go through no problem) and I am not in Sandbox mode.

Edit: I’ve also tried using min_tag_id=\(nextMinTagId), still do not receive pagination in the next request.


Seems like:

1) You are using the Instagram Developer API with what seems like an authorized APIKey, and you mentioned you are NOT in Sandbox, so you’re in a the Production environment for that api.

I’m trying to get 100, 200, or maybe 500 photos from a single tag

2) This means, combined with returns 20 images and a pagination json, that for 100, you need to make 5 calls minimum (100/20 == 5), 200 == 10, 500 = 25.

3) According to the developer documentation rate limits, the overall cap on Production is 5000 req/hour, with several APIs restricted to a much smaller limit (some are 30/60 req/hour). I’m not sure I see the exact tag rate limit you are hitting, but since the question mentions:

for probably 6 hours now to no avail

it’s also possible you’ve just been hitting the overall hourly request limit each hour.

I definitely know that this is not an answer that I enjoy giving, because it’s essentially saying: you're stuck. I’ve actually played with the rate limits myself before, and I find them extremely limiting (pun fully intended). The only other option, albeit not as “above board”, is to scrape Instagram itself for the information you need. I say it’s not as “above board” because if you needed info not found on a web scrape, you could theoretically scrape the mobile API through some minor reverse engineering (ie using an HTTP proxy to spoof mobile traffic systematically).

In the end, the API Instagram publishes is definitely very limited, and will face rate limits for the foreseeable future (unless you can get those somehow lifted in a specific partnership they somehow deem worthy, although I’m not sure how this could be approached).