Getting Started

This document explains how to successfully call the Instagram Graph API with your app and get an Instagram Business User's media objects. It assumes you are familiar with the Graph API and Facebook Login, and know how to perform REST API calls. If you do not have an app yet, you can use the Graph API Explorer instead and skip steps 1 and 2.

Before You Start

You will need access to the following:

1. Configure Facebook Login

Add the Facebook Login product to your app in the App Dashboard.

You can leave all settings on their defaults. If you are implementing Facebook Login manually (which we don't recommend), enter your redirect_uri in the Valid OAuth redirect URIs field. If you will be using one of our SDKs, you can leave it blank.

2. Implement Facebook Login

Follow our Facebook Login documentation for your platform and implement Facebook Login into your app. Set up your implementation to request these permissions:

3. Get a User Access Token

Once you've implemented Facebook Login, make sure you are signed into your Facebook Developer account, then access your app and trigger the Facebook Login modal. Remember, your Facebook Developer account must be able to perform Tasks on the Facebook Page connected to the Instagram Business User account you want to query.

Once you have triggered the modal, click OK to grant your app the instagram_basic and manage_pages permissions.

The API should return a User access token. Capture the token so you can use it in the next few queries. If you are using the Graph API Explorer, it should be captured in the Access Token field automatically:

4. Get the User's Pages

Query the GET /me/accounts endpoint (which translates to GET /{user-id}/accounts, based on your token). Don't forget your access token, which you must include with all queries:

curl -i -X GET \
 "https://graph.facebook.com/v3.2/me/accounts?access_token={access-token}"

This should return a collection of Pages that the current Facebook User can perform Tasks on:

{
  "data": [
    {
      "access_token": "EAAJjmJ...",
      "category": "App Page",
      "category_list": [
        {
          "id": "2301",
          "name": "App Page"
        }
      ],
      "name": "Metricsaurus",
      "id": "134895793791914",  // capture the Page ID
      "tasks": [
        "ANALYZE",
        "ADVERTISE",
        "MODERATE",
        "CREATE_CONTENT",
        "MANAGE"
      ]
    }
  ]
}

Capture the ID of the Page that's connected to the Instagram Business User you want to query. Keep in mind that your app users may be able to perform tasks on multiple Pages, so you eventually will have to introduce logic that can determine the correct Page ID to capture (or devise a UI where your app users can select the correct Page for you).

5. Get the Page's Instagram Business Account

Use the Page ID you captured to query the GET /{page-id}?fields=instagram_business_account endpoint:

curl -i -X GET \
 "https://graph.facebook.com/v3.2/134895793791914?fields=instagram_business_account&access_token={access-token}"

This should return the Instagram Business User ID that's connected to the Page.

{
  "instagram_business_account": {
    "id": "17841405822304914"  // Connected Instagram Business User ID
  },
  "id": "134895793791914"  // Page ID
}

Capture the Instagram Business User ID.

6. Get the Instagram Business User's Media

Use the Instagram Business User ID you captured to query the GET /{ig-business-user}/media endpoint:

curl -i -X GET \
 "https://graph.facebook.com/v3.2/17841405822304914/media?access_token={access-token}"

This should return all of the Media nodes on the Instagram Business User:

{
  "data": [
    {
      "id": "17918195224117851"
    },
    {
      "id": "17895695668004550"
    },
    {
      "id": "17899305451014820"
    },
    {
      "id": "17896450804038745"
    },
    {
      "id": "17881042411086627"
    },
    {
      "id": "17869102915168123"
    }
  ],
  "paging": {
    "cursors": {
      "before": "QVFIUkdGRXA2eHNNTUs4T1ZAXNGFxQTAtd3U4QjBLd1B2NXRMM1NkcnhqRFdBcEUzSDVJZATFoLWtXMWZAGU2VrRTk2RHVtTVlDckI2NjN0UERFa2JrUk4yMW13",
      "after": "QVFIUmlwbnFsM3N2cV9lZAFdCa0hDeV9qMVliT0VuMmJyNENxZA180c0t6VjFQVEJaTE9XV085aU92OUFLNFB6Szd2amo5aV9rTlVBcnNlWmEtMzYxcE1HSFR3"
    }
  }
}

If you are able to perform this final query successfully, you should be able to perform queries using any of the Instagram API endpoints — just refer to our various guides and endpoint references to learn what each endpoint can do and what permissions they require.

Next Steps

  • Develop your app further so it can use any other endpoints it will need, and keep track of the permissions each endpoint requires
  • Complete the App Review process to request approval for all of the permissions your app will need so your app users can grant them while your app is in Live Mode
  • Switch your app to Live Mode and market it to potential users

Once your app is in Live Mode, any Facebook User who you've made your app available to can access an Instagram Business User's data, as long as they have a Facebook User account that can perform Tasks on the Page connected to that Instagram Business User.