Can Instagram posts be easily retrieved?

Mike Wang

Displaying Instagram posts on your website can be unexpectedly confusing. Most developers’ first thought is to use the Instagram API to pull in content. Unfortunately, Instagram’s API requires clients to use the decidedly complex OAuth 2.0 protocol. Even worse, the API is being deprecated in July 2018 (per this announcement), so any work done with the API now will need to be redone in six months anyway.

Fortunately, if all you want to do is display a few instas from a single user on your site, there’s an easier way.

GET requests to URLs of the form${username}/?__a=1 will return a JSON object containing the 12 latest posts by the user ${username}. For example, returns the following JSON:

screenshot of long JSON objectThis goes on for 9 more kilobytes.

After a quick JSON.parse(), we now have an Object we can comb through to get the data we want. Let’s call this Object data. If we just want a neat little Array of images, we can do a map():

const posts = => {
  return ({
    image: c.display_src,
    caption: c.caption,
    date: new Date( * 1000),
    likes: c.likes.count,
    comments: c.comments.count,

There! posts now contains 12 Objects, each containing information about an Instagram post:

screenshot of console.log of posts variable

From here, we can create an <img/> element for each post and style them to our heart’s content.

We can also make each image link back to the original post on Instagram. In the original JSON, each image Object also comes with a code property set to a string like 'BYgmA03Abn7'. Add that property to your mapping function, assemble an href like this:

const href = "" + posts[0].code;

wrap each <img/> element inside an <a/>, add the href, and you’re done!


Last updated by on .

2 thoughts on "Can Instagram posts be easily retrieved?"

  1. Tom says:

    Hey Mike,

    Thanks for the writeup! Do you see a possibility to also gather the likes and comments and Sum them up for these last 12 posts? I imagine it would be relatively easy but iā€™m no expert šŸ™‚

  2. Mike Wang says:

    Hi Tom,

    That’s definitely possible. The easiest way to do this is with a forEach() loop:

    Let’s say you already have the `posts` variable like above (just an array of 12 objects, each representing an insta post). Create a variable like `commentCountTotal` and set it to 0. Then, use the forEach() loop to go through each object in `posts` and add the number of comments to `commentCountTotal`. When the forEach() loop is done, `commentCountTotal` will have the total number of comments in those 12 insta posts.

What Are Your Thoughts?

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