technology and zen of life

“A heisenbug (named after the Heisenberg Uncertainty Principle) is a computer bug that disappears or alters its characteristics when an attempt is made to study it.”

Instagram – Using the API

First a short introduction on Instagram, it is an iphone app for taking pictures, adding filters to make them look retro, and then for sharing them with sites like Twitter, Flickr, Tumblr, and Facebook, more importantly, it’s a simple social network of other people’s photos. You can “like” or comment on the photos, and see what’s new. It’s easy and doesn’t take much time or effort. This is one of the reasons it has become so popular so quickly.

What is also good to know is that Instagram has recently released an API which the user’s can use to fetch pictures that users upload to the website. In this article I want to discuss that API and how to use it to make the most out of it.

Firstly there are a number of ways in which you can fetch photographs….
1. Photos from a certain user
2. Photos which have been tagged with a specific keyword
3. Photos based on a geographic location
4. And finally photos which are most popular recently.

Before you start with accessing lets look at the initial steps.

Firstly you need to register your application with Instagram, this will provide you with a unique client_id and client_secret which you would need to continue further in your development.

After you have the client registered the next step is to get an authentication token. This step is quite important.
To get your authentication token you need to visit the following url[ClientID]

While replacing the [ClientID] with the ID you got in the first step and the [callbackuri] with your callback uri. If you were not already logged in it will ask you to authenticate and then return to your callbackuri after authentication with your authentication token attached at the end of the url like


Where CODE is your authentication code.

The next part is actually sending and receiving updates from the instagram website. I would be making use of the jquery as it simplifies things while placing your call to instagram to fetch the images.

        type: "GET",
        dataType: "jsonp",
        cache: false,
        url: "[UserID]/media/recent/?access_token=[CODE]",
        success: function(data) {...}

The userID used here is your ID and not the login name. It is a numeric number, if you can’t find it leave a comment and I will help you with it.
This would return the data which is an object which contains the returned images and their properties. The various data endpoints are described at Instagram developer page. How ever if you just want to get the image and the link you can use something like this as the function:

 function(data) {
for (var i = 0; i < 10; i++) {
$(".pics").append("<a target='_blank' href='" +[i].link +
"'><img src='" +[i].images.low_resolution.url +"'></img></a>");

This would fetch the first 10 images returned and display them in the div pics. You should include an empty div called pics in your html for this to work. and this function should be included as a javascript in the head of your page.

The url in the function can be replaced to fetch different types of pictures:

For most popular pictures:
url:  "[ClientID]&access_token=[CODE]"

The 4 latest Popular pics:

For recent pics of a User:
url:  "[CODE]"

My 4 last pics:

For most recent pictures with a specific tag:
url:  "[TAG]/media/recent?client_id=[ClientID]&access_token=[CODE]"

Here are the last 4 images with the tag hdr :

For most recent pictures from a specific location:
url:  "[LAT]&lng=[LNG]&distance=[DST]

Where LAT and LNG are latitude and longitude of the place and DST is the radius of the area in meters (max 5000 meters)

For example here you can see the last few pics uploaded from Amsterdam 🙂

Have fun with the API and feel free to post links to your web pages where you use it.
Also if you have any questions let me know!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

114 Responses

  1. […] La respuesta no se ve como una jsonp objeto?? Tengo el ejemplo de código a partir de aquí, […]

  2. JB says:

    how to show a location based images..only inages of a location like london(the images of london city,etc)).pls help

  3. Karen says:

    Do you know how to find the actual identity of an Instagram account? How can you tell if the name and the photos that they are posting are actually of that person? Reason I am asking is because my nine year old daughters were direct messaged by someone on Instagram asking them to take naked photos and he sent them one of him. I want to find this guy and turn him into the authorities. Thank you.

  4. jay nickson says:

    Thanks for your work.

    Any chance of getting a complete HTML example that uses client_Id and access code and the callback processing so, after inserting real client_id we have a running example?

    If a sensible request: please do not combine url and callback, we can all combine things, and it is harder to tease out separations from multi-pathing pages. Seeing the minimal linear code is, for me, the best and fastest way to see what is happening.

  5. […] can see lots of notes about how to use the API that show you  ways to display hashtag-sorted images yet itself doesn’t […]

  6. […] Instagram – using the api | api […]

  7. […] Instagram – using the api | api […]

  8. […] Instagram – using the api | api […]

  9. […] Instagram – using the api | api […]

  10. […] Instagram – using the api | api […]

  11. […] website to fetch images. This includes examples for receiving most popular, location based or tag Download Instagram – Using the API | API | […]

  12. […] website to fetch images. This includes examples for receiving most popular, location based or tag Download Instagram – Using the API | API | […]

  13. taresh says:

    how to get all images from instagram?

  14. PC says:

    Hi Guys,

    Can I have All possible attributes shared by instagram for the api trying to register via them.

    Thanks in advance.


  15. PC says:

    All possible attributes shared by instagram for the api trying to register via them

  16. Monika P says:

    Hi Navin,
    Thanks for sharing this post .
    I am new to Instagram development .

    I want to display/download images/videos from instagram account to my webapplication using Microsoft technologies like etc .

    Can you please guide me on this?
    From where should I have to start ? and which IDE should I use ?

    Thanks in advance.

  17. rob says:

    How can the thumbnail size be changed or made to be responsive? And thank you for such an amazing run through of the instagram api.

  18. rob says:

    How quickly does the feed refresh with new images?

  19. davidmabe24 says:

    Hi, I have a doubt. access_tokens are unique to a user. So i need to retrieve access_token data from url always for different users using my app. But i didn’t find a way to detect instagram authorization, after which i should take the url. Please suggest what to do.


    • Navin says:

      If you are creating a access token per user then you need to call the reg URL and wait for the call back from instagram. You don’t need to worry about authentication.[ClientID]

      And then instagram will reply by calling the url

      Next step is to get the ACCESS_TOKEN

      For this you need to call the instagram API with the following parameters
      client_id: your client id
      client_secret: your client secret
      redirect_uri: Note: this has to be the same value as in the authorization request.
      code: the exact code you received during the authorization step.
      For example, you could request an access_token like so:[ID]&client_secret=[Secret]&grant_type=authorization_code&redirect_uri=[URI]&code=[CODE]

  20. Jagdish says:

    Can I Post data or share data on Instagram using api?

  21. poorusher says:

    Hey, this is great.

    Do you happen to know where the documentation is for this stuff:[i].images.low_resolution.url

    I managed through trial and error to get[i].link but I cannot find any info on the Instagram API site on the other parameters.


  22. mike says:

    Any way to combine searches? I want to do a specific hashtag from a specific lat/long location.

  23. freshprinc says:

    thank you for this
    i get this error [13:19:24.466] TypeError: is undefined

  24. Octopus says:

    It would be helpful if you provided a link to the page where we get our client id codes from.

  25. srinivas says:

    how to do the same in ios app, I mean i want fetch the images in ios app, please suggest if anyone aware of this

  26. […] via Instagram – Using the API | API. […]

  27. Thank for your tutorial.

  28. Daniela says:

    hi, Where can i find the user id?

  29. Pankti says:

    hi, i am trying to download content from Instagram. i have register my website in my Instagram developer account.
    Can you help me to start with this task? how to get pictures from account.

  30. Biswanath Bose says:

    What is the process, to share some image fraom a website to instagram, Have you nay PHP code for this. How can i register in instagram, through browser

  31. Shivani says:

    i want to fetch particluar user images for some particular tags,how can it be done?

  32. Ximena says:


    I am not sure what Im doing wrong, but I cant seem to find the client id and secret id. When i click on “register a client”, instagram redirects me to my “edit profile” page. There is no way I can add a cient???

    Is this because I am using my own instagram account (stereotipa)? Do I need to create some sort of developper account?

    Please, would appreciate some light on this!

    Thanks in advance,


The views expressed on this blog are personal. We do not claim to be a representative voice of the views of any organisation whatsoever. We are not responsible for the content present on the blogs to which we have linked.Views expressed are solely that of the author and does not reflect a collective opinion of contributors.
%d bloggers like this: