Zac Fukuda
067

Get Instagram Media with Facebook API

“I want to show our pictures from Instagram on our website,” says one of my clients. Actually, more than one of them say so.

So here is how to get URLs of pictures posted in your Instagram account. Once you get the URLs, all you have to do is to embed that URLs to <img src="" />.

(As of this writing, the latest Facebook/Instagram API version is v22.0. All examples of API URL are assumed to be this version.)

Overview

Meta platform overview regarding Instagram media
Meta platform overview regarding Instagram media

Prerequisites

  • Must have a Facebook user account.
  • Must have a Facebook Page.
  • Must have an Instagram business/creator account.
  • Must have a Meta app. (app ID and secret)
  • Your Facebook user account must have an administration role of your Facebook Page.
  • Your Facebook Page must be connected to your Instagram business/creator account.
  • You Meta app must have the Instagram product.

Why not Instagram API and Login?

There are two ways to get your Instagram media: Instagram API with Instagram Login and Facebook API with Facebook Login.

Instagram API with Instagram Login offers you a quick start to use your Instagram medias. But the long-lived access token via Instagram Login is valid for only sixty days. Which means you need to renew your token every couple months. That is a lot of work. The long-lived page access token via Facebook Login, on the other hand, has no expiration day. You can use it as long as you want, theoretically, for good and bad. (There are more probability your token would be exposed and misused.)

For a static marketing website that simply needs to display Instagram media, the long-lived page access token fits best to the business needs. The first implementation is cumbersome. Yet once you get a long-lived token, you will have ease.

1. Get a short-lived user access token

User access token

  1. Visit https://developers.facebook.com/tools/explorer/.
  2. Select your Meta app in Meta App field.
  3. Add the following permissions:
    • instagram_basic
    • pages_read_engagement or pages_show_list
  4. Select “Get User Access Token” in the User or Page field.
  5. Click “Generate Access Token.”
  6. During the login:
    1. Select your Facebook Page.
    2. Select your Instagram account.
Meta platform overview regarding Instagram media

Now you have logged into your Meta app, and have your user access token.

User ID

After you logged in to your Meta app on the Explorer,

  1. Type me?fields=id,name in the path field.
  2. Click “Request”.

Now you have your own user ID.

{
  "id": "YOUR_USER_ID",
  "name": "YOUR_NAME"
}

2. Get a long-lived user access token

About Long-lived Access Token.

Once you have a user access token, you can either keep using the API Explorer or your computer’s terminal. I prefer using my terminal with curl command.

curl -X GET 'https://graph.facebook.com/v22.0/oauth/access_token?grant_type=fb_exchange_token&client_id=META_APP_ID&client_secret=META_APP_SECRET&fb_exchange_token=YOUR_SHORT_LIVED_USER_ACCESS_TOKEN'

Response:

{
  "access_token": "YOUR_LONG_LIVED_USER_ACCESS_TOKEN",
  "token_type": "bearer"
}

You can still use a short-lived user access token until it expires.

3. Get a long-lived page access token

About Long-lived Page Access Token.

curl -X GET 'https://graph.facebook.com/v22.0/YOUR_USER_ID/accounts?access_token=YOUR_LONG_LIVED_USER_ACCESS_TOKEN'

Response:

{
  "data": [
    {
      "access_token":
      "YOUR_LONG_LIVED_PAGE_ACCESS_TOKEN",
      "category":"",
      "category_list": [
        {
          "id": "19313363…",
          "name": "Some category"
        }
      ],
      "name": "Your Facebook Page name",
      "id": "12869185…",
      "tasks": ["MODERATE", "MESSAGING", "ANALYZE", "ADVERTISE", "CREATE_CONTENT", "MANAGE"]
    }
  ],
  "paging": {
    "cursors": {
      "before": "xxxx…",
      "after": xxxx…"
    }
  }
}

This is a list of Facebook Pages to which you have access.

4. Get your Instagram ID

Here, the ID is not what you put into your profile. It's an ID Instagram allocates for you programmatically. This ID is always a numeric string.

There is no consistent method to know your Instagram ID. For the latest method, you can refer to Instagram how to get my user id from username? on StackOverflow.

As of April in 2025, https://www.instagram.com/web/search/topsearch/?query=<username> URL works. You don't even need a curl request. Just type the URL in a browser and you will get a JSON response.

If any methods in the StackOverflow thread don’t work, you can check the Meta’s official developer documentation about Instagram API. The document is very likely to change in the future.

5. Get IG User media

About IG User media - Reading.
About IG Media.

curl -X GET 'https://graph.facebook.com/v22.0/YOUR_INSTAGRAM_ID/media?access_token=YOUR_LONG_LIVED_PAGE_ACCESS_TOKEN'

Response:

{
  "data": [
    { "id":"18066839…" },
    …
  ],
  "paging": {
    "cursors":  {
      "before": "xxxx…",
      "after": "xxxx…"
    },
    "next": "https:\/\/graph.facebook.com\/v22.0\/YOUR_INSTAGRAM_ID\/media?access_token=YOUR_LONG_LIVED_PAGE_ACCESS_TOKEN&limit=25&after=xxxx…"
  }
}
  • By default the API returns 25 medias.
  • By default the API returns only id property of media.

The document does not say anything about the query string limit and fields but you can add them to the URL.

Each media has a media_type property. The value of which can be CAROUSEL_ALBUM, IMAGE, or VIDEO. All media types have a media_url property. The media_url of VIDEO media is a video, i.e. an mp4 file, which you may or may not want to display on your website. VIDEO medias have an extra property thumbnail_url, which is always a image file.

So all fields you need to display Instagram media on your website are:

  • media_type
  • media_url
  • thumbnail_url

The example curl command that get ten medias with these fields is:

curl -X GET 'https://graph.facebook.com/v22.0/YOUR_INSTAGRAM_ID/media?limit=10&fields=media_type,media_url,thumbnail_url&access_token=YOUR_LONG_LIVED_PAGE_ACCESS_TOKEN'

Response:

{
  "data": [
    {
      "media_type": "IMAGE",
      "media_url": "https:\/\/scontent.cdninstagram.com\/v\/xxxx.jpg?…",
      "id": "18066839…"
    },
    …
  ],
  "paging": {
    "cursors": {
      "before":  "xxxx…",
      "after": "xxxx…"
    },
    "next": "https:\/\/graph.facebook.com\/v22.0\/YOUR_INSTAGRAM_ID\/media?limit=10&fields=media_type,media_url,thumbnail_url&access_token=YOUR_LONG_LIVED_PAGE_ACCESS_TOKEN&after=xxxx…"
  }
}

Now you can use your Instagram media URLs to do whatever you want.