Tero Auralinna's blog about intriguing world of web development. Tweaking pixels since the '90s.

How to fetch your public photos from Instagram without the API

Published on October 24, 2019. Edited on June 28, 2020.

This is a short demo about how you can fetch your Instagram photos without the usage of Instagram API, which requires a user to authenticate.

Embedded content:

This technique is based on the <script> tag found from the Instagram profile page. Script tag has the data, which we will parse by regular expression.

const instagramRegExp = new RegExp(/<script type="text\/javascript">window\._sharedData = (.*)<\/script>/)

The following function will fetch the profile page. It parses the Instagram data to JSON and returns an array of objects holding an image page URL, image source URL, and caption.

const fetchInstagramPhotos = async (accountUrl) => {
  const response = await axios.get(accountUrl)
  const json = JSON.parse([1])
  const edges = json.entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges.splice(0, 8)
  const photos ={ node }) => {
    return {
      url: `${node.shortcode}/`,
      thumbnailUrl: node.thumbnail_src,
      displayUrl: node.display_url,
      caption: node.edge_media_to_caption.edges[0].node.text
  return photos

Calling the function:

try {
  const photos = await fetchInstagramPhotos('')
  // Do something with the photos
} catch (e) {
  console.error('Fetching Instagram photos failed', e)

Note that you need to wrap this into an async function.

Note that this might break anytime if Instagram changes its source code, and this works only for the public profile. Also, it's possible to fetch only 12 images with this technique.