Apidog

All-in-one Collaborative API Development Platform

API Design

API Documentation

API Debugging

API Mocking

API Automated Testing

Instagram Basic Display API Guide: Fetch Instagram User Info

Lixiong Wei

Lixiong Wei

Updated on November 29, 2024

Instagram, with its visually-driven platform, has become a powerful tool for businesses, developers, and creators. To enhance the user experience and facilitate seamless integration, Instagram provides two essential tools: Instagram Graph API and Instagram Basic Display API. In this article, we'll focus on the capabilities of Instagram Basic Display API and how it can be leveraged to optimize your Instagram presence.

šŸ’”
Apidog is an All-in-one API development platform which allows you to easily design, test, and document your API. For the one who wants to test Instagram API, using Apidog is always the easiest solution.
button

Instagram Basic Display API

The Instagram Basic Display API is a tool provided by Instagram (a subsidiary of Facebook) that allows developers to access basic user information, media content, and other data from Instagram accounts. This API is specifically designed for scenarios where read-only access to user data is required, making it suitable for applications that focus on displaying Instagram content or providing personalized experiences.

Set up before accessing to API

Requirements:

1. A Facebook developer account.

2. A tester Instagram account.

3. A web page (URL) for redirect, to grant permission for the application to access Instagram.

Steps for setup:

  1. In developer page, click on Create App. Select Other to proceed.
create app facebook

2. choose customer as app type for Instagram basic display API

choose app type

Next, fill in your information (App name, contact email) and proceed

3. Set platform URL. Go to setting > basic, click on add platform at the bottom and enter your URL (The web page mentioned in requirement).

edit basic info
update website url

4. Set up Instagram Basic API on dashboard

set up instagram basic api

After the app is created, a form will appear with some things to be saved and to be filled in.

check api info

App ID and secret will be needed later.

5. Enter the same URL as before in Valid OAuth redirect URI, Deauthorization callback URL and data deletion request since this app is for testing purpose.

client oauth uri

Add tester into the form, for example, if Alice want to retrieve Bobā€™s information, then enter Bob account username.

add app roles

After adding a user, the status of the user will be pending since authorization from user is needed. It is recommend to use the tester account.

6. Login to your tester Instagram account, go to settings> website permission> Apps and Websites> Tester Invites. Accept the test invitation.

login to tester instagram account

Basic set up is complete!

How to request for authorization?

Authorization code is needed before using API, the survival time of this authorization code is 1 hour. To obtain the code, enter the URL in this form:

https://api.instagram.com/oauth/authorize?client_id={app-id}&redirect_uri={redirect-uri}
&scope=user_profile,user_media
&response_type=code

Explanation for the attributes:

ā€ƒApp-id: The application id is the app-id, this can be found in basic display under Instagram basic display app.

ā€ƒredirect_uri: the same URL as valid OAuth redirect URI.

redirect uri

Remember not to leave space for the whole URL.

After click on enter, it will go to the page for allowing authorization.

allow auth

After allowing all access, it will redirect to the your own url, with code parameter attached to url, looks like

https://www.example.com/?code=ABCD......#_

The authorization code is the one after code=, remember to delete the #_ since this is not the part of authorization code.

How to use Apidog to use exchange the code to access token?

Apidog is an All-in-one API development platform which allows you to easily design, test, and document your API. For the one who wants to test Instagram API, using Apidog is always the easiest solution.

button

Convert the authorization code to access token

Switch method to POST, input URL:

https://api.instagram.com/oauth/access_token

Added these parameters that is needed:

  • client_id = Instagram App ID
  • client_secret = Instagram App secret
  • code = Authorization code obtained
  • grant_type = authorization_code (This value is set)
  • redirect_uri = your own URI
Set up with Apidog

Click on send, the access token will be returned in form of JSON file, looks like:

{
"access_token": "IGQWR9......",
"user_id": 7666070400110123
}

Note: the token is also valid for 1 hour

How to use access token and user ID to query account information?

There are brunch of features can be fetch using Instagram Display Basic API, here below are two examples of information retreiving.

  1. access an account's basic information

Sample request using curl:

curl -X GET \  'https://graph.instagram.com/{user-id}?fields=id,username&access_token={access-token}'

Parameters explanation: Ā 

  • User_id: get from previous step
  • Access_token: from previous step
  • Fields: can be partially optional. Ā There are 4 type of fields available:
1. Account_type: account type 
2. Id: user_id 
3. Media_count: number of posts
4. Username: account name

If you want to get all of these four, enter all of them separate by comma (,)

Set up in Apidog

The return result:

2. Retrieve userā€™s post information

Sample request:

curl -X GET \ 
'https://graph.instagram.com/me/media?fields=id,caption&access_token=IGQVJ...'

Set up in Apidog:

For more features with Instagram display API, refer to:

Get Profiles and Media - Instagram Platform - Documentation - Meta for Developers

Conclusion

In conclusion, the Instagram API opens up a world of possibilities for developers to interact with the Instagram platform and create innovative applications. From accessing user information and media content to posting new photos and videos, the diverse range of endpoints allows developers to tailor their applications to specific needs.

How to Fetch GraphQL with API?Tutorials

How to Fetch GraphQL with API?

Discover how to fetch GraphQL data efficiently using the Fetch API and Apidog. Learn advanced techniques, optimize performance, and secure your API for robust applications. Download Apidog for free to streamline your API workflows.

Ashley Innocent

November 28, 2024

What is Faker.js and How You Can Use It in Apidog for Generating Mocking DataTutorials

What is Faker.js and How You Can Use It in Apidog for Generating Mocking Data

Discover what Faker.js is and how to use it in Apidog to generate mock data for API testing. Learn step-by-step instructions, practical examples, and best practices.

Ashley Innocent

November 27, 2024

How Apidog Enhances API Development Efficiency for Backend Developers?Tutorials

How Apidog Enhances API Development Efficiency for Backend Developers?

Backend developers often struggle with debugging and documentation. Apidog simplifies API management with tools for design, testing, and documentation, boosting efficiency.

Oliver Kingsley

November 26, 2024