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.
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:
- In developer page, click on Create App. Select Other to proceed.
2. choose customer as app type for Instagram basic display API
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).
4. Set up Instagram Basic API on dashboard
After the app is created, a form will appear with some things to be saved and to be filled in.
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.
Add tester into the form, for example, if Alice want to retrieve Bobās information, then enter Bob account username.
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.
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.
Remember not to leave space for the whole URL.
After click on enter, it will go to the page for allowing authorization.
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.
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
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.
- 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 (,)
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:
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.