This article will discuss about how to use Instagram API with step-by-step integration guide and full documentation list. Let’s get started!
Overview of Instagram API
Instagram is a photo and video-sharing platform and is one of the leading social media platforms in the world with over 1 billion people using the app every month. Instagram API for developers allows them to publish content, manage content, and access public data. Developers can use the API to create applications that interact with Instagram. Instagram API for websites allows businesses to manage their Instagram presence more effectively and track their performance on the platform.
Also read: How to use Shopify API; a step-by-step integration guide and full documentation list
List of Instagram developer API and functionalities
Does Instagram have an API? Yes Instagram API helps developers develop programs that interact with Instagram. Here are some developer API Instagram and their functionalities listed below
- Instagram Graph API – Your app can access information from business and personal accounts using Instagram Graph API. You can use the API to obtain and publish their media, manage and respond to comments left on your content, locate content that has been hash tagged, find media where you have been @mentioned by other Instagram users, and obtain basic metadata and stats about other Instagram Businesses and Creators. You can think of Instagram Graph API as an Instagram business API because it was created specifically for businesses and creators.
- Instagram Basic Display API – You can access the fundamental profile, images, and videos using this API. The Instagram Basic Display API to create applications that news feeds and photo galleries.
- Instagram Messaging= Your app can handle your Instagram messages for your professional account using Instagram messaging API. You can use this API to send and receive messages from other Instagram users.
- Sharing to stories – You can share material from your app to Instagram using this API. It can be used to create applications that let users post their images, videos, links to their stories
- Sharing to feed – You can share content from your app to Instagram Feed using this API.
- Embedding – You can use this API to embed Instagram stories on your API and website. You can use it to create applications that lets people view Instagram content without leaving the app.
Also read: How to use Stripe API; a step-by-step integration guide and full documentation list
How to use Instagram API – step-by-step integration guide
Like most APIs Instagram Open API requires you to get a unique key that will let you access API features and capabilities on your website or Apps. Before using Instagram API you need to have:
- A Facebook account
- A Facebook page, a dedicated testing page
- An Instagram Account
You need to turn your Instagram account into a business account and link it to your Facebook page. Here are step-by-step integration guide
- Head to the App Dashboard of your Facebook app.
- On the sidebar, click the button that says Product.
- Click set-up on the Facebook Login Product card.
- Enter your Facebook Login setting. Make sure all the options are set to default.
- Finish implementing Facebook Login into your app depending on your target device (iOS, Web, Android. bsite/instagram-api-examples
- In your implementation, configure it to request these permissions:instagram_basic, pages_show_list
- Return to your app and Login using your Facebook credentials. Ensure you are also logged into your Facebook Developers account.
- Click Ok to give your app the permissions (instagram_basic, pages_show_list) you set up earlier.
- You should now see instagram api access token on the screen.
You can use this Instagram API access key to retrieve your user pages, Instagram Business Object, and Media objects.
Also read: How To Use YouTube API; A Step-By-Step Guide To Integrate And Full Documentation List
Instagram API documentation n references
Instagram API documentation references offer detailed instruction on how to use Instagram API. The Instagram API contains the following
- Overview – the overview acts as an introduction to Instagram API docs offers instructions on how to use the API.
- Get Started- Explore the API using the API explorer tool and find frequent requests easily.
- Guides – Provides in-depth instructions on how to use the API to carry out specific tasks such as gather user data, upload photographs, and moderate comments.
- References- the section provides detailed references of all the endpoints and fields available in the API.
The Instagram API documentation is an excellent resource to build apps, integration, and other tools. The documentation is easy to understand and follow. It is a great starting point for any coder wanting to learn the API.
There are other useful resources to learn more about API given below
- The Instagram Developer Blog: Gives details about the latest tools to manage your business.
- The Instagram Developer Forum: It is a community of 1000 of developer from countries around the world. It is a great place to ask questions and get help from other developers.
- The Instagram API SDKs: The Instagram API SDKs provide a convenient way to use the API in a variety of programming languages.
These are all the resources you need to build a great program. We recommend you read the documentation in chronological order to avoid confusion. There are several great examples to help you learn to use the API.
Instagram API examples
Instagram API is a powerful tool to build the apps or integration. In this section, we focus on some Instagram API examples. The Instagram API is frequently used to create applications that let people browse and engage with Instagram content. It can also be used to build applications to let users manage their accounts or provide insights into Instagram data. Before you start you need
- A Meta developer account
- A registered Meta App with basic settings configured.
- Your app secret
- An Ad account
- A Page access token
How to use Instagram API Python
To use Instagram API Python you will need to
Step1: Install Python on your computer.
For this we will be using a Windows computer. You can check the program with a simple code
#!/usr/bin/env python
import sys
sys.stdout.write(“hello from Python %sn” % (sys.version,))
When you run the hello.py you should get the output
>python hello.py
hello from Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)]
Step2: Install the Instagram API Python library.
The Instagram API Python library is available on pypi module. You can install it with the following command:
pip install instagram-python
Step3: Configure your Python environment with your API keys.
Use your API Key to configure to your Python environment, you will need to add the following variables.
INSTAGRAM_API_KEY=YOUR_API_KEY
Step4: Write Python code to make a request to API
Create a project file test.py with the following content Replace {app-id}, {access-token}, {appsecret}, and {adaccount-id} with your values.
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
my_app_id = ‘{app-id}’
my_app_secret = ‘{appsecret}’
my_access_token = ‘{access-token}’
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount(‘act_{{adaccount-id}}’)
campaigns = my_account.get_campaigns()
print(campaigns)
Remember to test your install with If it complains about an expired token, request a new Page Access Token and retry.
python test.py
You should see the results on the terminal window. If there are complaints about expired tokens you may have request new Page Access and retry.
How to use Instagram API Javascript
The Instagram API Javascript is distributed through Node.js package.
Step1: Open your command terminal window and create a new project folder. Create, configure, and install your project with the following command
You can update your configuration settings later by editing the package.json file directly.
Step2: Install the SDK
Install the SDK package with the following command:
npm install –save facebook-nodejs-business-sdk
Step3: Modify the project file
Open the index.js file and add the following code. Replace {access-token}, and {adaccount-id} with your values.
const bizSdk = require(‘facebook-nodejs-business-sdk’);
const accessToken = ‘{access-token}’;
const accountId = ‘act_{{adaccount-id}}’;
const FacebookAdsApi = bizSdk.FacebookAdsApi.init(accessToken);
const AdAccount = bizSdk.AdAccount;
const Campaign = bizSdk.Campaign;
const account = new AdAccount(accountId);
var campaigns;
account.read([AdAccount.Fields.name])
.then((account) =>{
return account.getCampaigns([Campaign.Fields.name], { limit: 10 }) // fields array and params
})
.then((result) =>{
campaigns = result
campaigns.forEach((campaign) =>console.log(campaign.name))
}).catch(console.error);
Step4: Test Your Install
Test your install with the following command
node index.js
You should see the result in your terminal window. If it complains about an expired token, request a new Page Access Token and retry.
How to use Instagram API PHP
For PHP we recommend you use Composer to install the SDK.
Step1: Install the SDK
In a new project folder, create composer.json with the following content. Replace {project-name}, {Your Name}, and {your@email.com} with your values.
{
“name”: “name/{project-name}”,
“type”: “project”,
“require”: {
“facebook/php-business-sdk”: “^8.0.3”
},
“authors”: [
{
“name”: “{Your Name}”,
“email”: “{your@email.com}”
}
]
}
Install the SDK by running the following command in your terminal window:
composer install
Step2: Create a Project File
Create a src/test.php file with the following content. Replace {app-id}, {access-token}, {appsecret}, and {adaccount-id} with your values.
<?php
require_once __DIR__ . ‘/../vendor/autoload.php’;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\CampaignFields;
$app_id = “{app-id}”;
$app_secret = “{appsecret}”;
$access_token = “{access-token}”;
$account_id = “act_{{adaccount-id}}”;
Api::init($app_id, $app_secret, $access_token);
$account = new AdAccount($account_id);
$cursor = $account->getCampaigns();
// Loop over objects
foreach ($cursor as $campaign) {
echo $campaign->{CampaignFields:
}
Step3: Test Your Install
Test your install with the following command:
php src/test.php
You should see the result in your terminal window.
How to use Instagram API tutorial Android
Here is how to use Instagram API tutorial Android
Step1: Create an Instagram developer account
- Go to Create an Instagram developer account. After you create an account you will be able to register.
Step2: Register your App and get client ID and client Secret.
To register your app, go to the Instagram Developer Dashboard and click on “Register App”. Fill out the form and click on “Register”. You will be given your client ID and client secret.
Step3: Add Instagram SDK to your project
The Instagram SDK is available for Android Studio. You can add it to your project by following these steps:
- Open your project in Android Studio.
- In the toolbar, click on “File” > “Settings”.
- In the “Plugins” tab, search for “Instagram SDK” and click on the “Install” button.
- Click on “Restart Android Studio”.
- Create an InstagramSession object and authenticate the user.
To create an InstagramSession object, you need to pass in your client ID, client secret, and the redirect URI that you specified when you registered your app. You can then use the InstagramSession object to authenticate the user.
To authenticate the user, you need to call the authenticate() method on the InstagramSession object. This will open a web browser where the user can log in to Instagram. Once the user has logged in, the web browser will close and the InstagramSession object will be authenticated.
- Make API calls to get user data, posts, and other information.
Once you have authenticated the user, you can make API calls to get user data, posts, and other information. To make an API call, you need to create an InstagramAPI object and pass in the authenticated InstagramSession object. You can then call the methods on the InstagramAPI object to get the data that you want.
Here are some examples of API calls that you can make: to get user profile information
InstagramAPI api = new InstagramAPI(session);
User user = api.getUser();
How to use Instagram JQuery API
Here are how to use Instagram JQuery API
Almost all Instagram feed plugins (like jQuery instagramFeed) that do not require the Instagram API have been broken since the latest Instagram changes.
To address this, I recommend using this jQuery script to display your Instagram feed on the webpage using the official Instagram Graph API and AJAX requests
Step1: Create a container to hold your Instagram feed.
<div id=”instagram-feed1″ class=”instagram_feed”></div>
Insert your Instagram authorization token into the jquery-feed-instagram-
graph.js. See How to get Instagram Feed Access Token for details .
// jquery-feed-instagram-graph.js
var token =’YOUR INSTGRAM TOKEN HERE’;
Determine the number of Instagram items to show. Default: 6.
// jquery-feed-instagram-graph.js
var limit = 8;
Insert the jquery-feed-instagram-graph.js after jQuery and done.
<script src=“/path/to/cdn/jquery.min.js”></script>
<script src=“/path/to/jquery-feed-instagram-graph.js”></script>
Step2: Apply your own CSS styles to the Instagram feed.
.instagram_feed {
overflow: hidden;
}
.instagram_feed .instagram_new {
width: 16.666%;
float: left;
padding: 0 1px 1px 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.instagram_feed img.insta-image {
position: absolute;
left: 0;
top: 0;
object-fit: cover;
width: 100%;
height: 100%;
transition: all 0.3s ease 0s;
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-ms-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
}
.instagram_feed .insta-link {
position: relative;
display: block;
background: #232323;
padding-top: 100%;
}
.instagram_feed .insta-link:hover .insta-image {
opacity: 0.2;
}
How to use Instagram API Nodejs
To learn to use Instagram API NodeJs you need to have
- Node JS installed on your computer.
- Working knowledge GraphQl
- Working Knowledge of Javascript
1. Create a Facebook App
Follow steps 1 to 3 from this link.
2. Get Access Tokens
Proceeding further requires app-specific keys and secrets which can be found here.
App ⇒ Dashboard ⇒ My products ⇒ Instagram Basic Display ⇒ Settings
App ID is required on the frontend only; backend requires both ID & secret. Since App secret can’t be shown to users, it’s kept as an environment variable on the server.
Also, add your frontend application’s URL to Valid OAuth Redirect URIs. localhost with https will work. Hosting static app on GitHub pages will do and is a better option.
Frontend
Use this piece of code on a static frontend site to get a short-lived access token. Short-lived access tokens are valid for 1 hour but can be exchanged for long-lived tokens (will do later on server-side).
Since our goal is to fetch user-related info and their Instagram photos, scopes are set to user_profile & user_media.
// Invoke this function on button click or whatever other use case
function setupInsta(){
let appId = “XXXXXXXXXXXXXX”;
let redUri = window.location.origin + “/insta”;
let url = `https://api.instagram.com/oauth/authorize?client_id=${appId}&redirect_uri=${redUri}&scope=user_profile,user_media&response_type=code`;
window.open(url, “_blank”).focus();
}
It will open authorization window on a new tab. After being authorized it will redirect to /insta page(as configured on the above code) with a query parameter containing code. That code will be used to fetch short-lived access token on the backend.
Next, the code & redirect URI are sent to the server for further processing.
axios.post(“https://your-server-url/init-insta”, { | |
code: ‘code-query-param-from-url’, | |
redirectUrl: ‘redirect-url’ // needs to be registered at fb developer console | |
}) | |
.then(({ data }) => { | |
// handle success case | |
}) |
Backend
It’s assumed that the backend has an endpoint for receiving code & redirect URI via any HTTP method.
Now, the next step is to get Short-Lived-Access-Token. The code is self-explanatory.
JSON-based POST won’t work. So form based request is sent via request.
/ data from frontend | |
let code = req.body.code; | |
let redirectUri = req.body.redirectUri; | |
let accessToken = null; | |
try { | |
// send form based request to Instagram API | |
let result = await request.post({ | |
url: ‘https://api.instagram.com/oauth/access_token’, | |
form: { | |
client_id: process.env.INSTA_APP_ID, | |
client_secret: process.env.INSTA_APP_SECRET, | |
grant_type: ‘authorization_code’, | |
redirect_uri: req.body.redirectUri, | |
code: req.body.code | |
} | |
}); | |
// Got access token. Parse string response to JSON | |
accessToken = JSON.parse(result).access_token; | |
} catch (e) { | |
console.log(“Error=====”, e); | |
} |
After Short-Lived-Access-Token is obtained, it needs to be exchanged with Long-Lived-Access-Token.
try {
let resp = await axios.get(`https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret=${process.env.INSTA_APP_SECRET}&access_token=${accessToken}`)
accessToken = resp.data.access_token;
// save accessToken to Database
} catch (e) {
console.log(“Error=====”, e.data);
}
For further API calls only the Long-Lived-Access-Token is used. As mentioned earlier, short-lived token has 1 hour validity. Similarly long-lived token has 60 days validity. i.e. the token just stored on DB needs to be refreshed before it expires.
3. Setup Token Refresh Service
To refresh token every 60 days, a cron job seems suitable. node-cron will serve best for this purpose.
import cron from ‘node-cron’;
import instaRefreshCron from “./crons/instaRefresh.cron”;
// run immediately after server starts
instaRefreshCron();
// refresh instaAccessToken eg: weekly(every Sat)
cron.schedule(‘* * * * * 7’, async () => {
await instaRefreshCron();
});
4. Fetch data
Finally, its time to fetch data from Instagram. We will be making use of the accessToken stored on DB. To learn more on what kinds of data can be fetched, visit this page.
try {
let instaAccessToken = “XXXXXX”; // get from DB
let resp = await axios.get(`https://graph.instagram.com/me/media?fields=media_type,permalink,media_url&access_token=${instaAccessToken}`);
resp = resp.data;
let instaPhotos = resp.data.filter(d => d.media_type === “IMAGE”).map(d => d.media_url);
// Got insta photos
} catch (e) {
console.log(e.response.data.error);
}
How to use iOS Instagram API
Before you learn how to use iOS API you need to create : Facebook Developer Account.
Step1: Create a Facebook App
- Go to the developer.facebook.com , click on My app to create a new app. After creating the app and are in the app navigation board, go to the Setting> Basic and sroll to the bottom of the page and Click on Add Platform.
- Choose iOS and add your iOS Bundle and shared secret, and save your changes.
- To get your BundleID just click on your project in Xcode, select your Target, then click on General, you will find your Bundle ID in Identity>Display Name.
- To get Shared Secret copy your App Secret and paste it in the Shared Secret.
Step2: Configure Instagram Basic Display
- Click Products, locate the Instagram product, and click Set up tp add to your app.
- Click Basic Display and go to the bottom of the page and Click Create New App. Now enter the name of the app you created.
- Next in Valid OAuth Redirect URIs, enter your website’s URL or any other website’s URL. Normally this would be a dedicated URI that can capture redirect query string parameters. Save the URL since you will be needing it later. In Deauthorize Callback URL, enter the copied URL again. Eventually you will have to change this to a URL that can handle deauthorization notifications, but for the purposes of this tutorial, you can re-use the above copied URL.
- Do the same forData Deletion Request Callback URL.
Step3: Add an Instagram Test User
- Navigate to Roles > Roles and scroll down to the Instagram Testers section. Click Add Instagram Testers and enter your Instagram account’s username and send the invitation.
- Open a new web browser and go to instagram and sign into your Instagram account that you just invited. Navigate to (Profile Icon) > Edit Profile > Apps and Websites > Tester Invites and accept the invitation.
Your Instagram account is now eligible to be accessed by your Facebook app while it is in Development Mode.
Instagram API cost
A common question asked by developers, is Instagram API free. There is no cost associated with using Instagram API but you need to first apply and be granted access by Instagram. To get access to Instagram API, first create a developer’s account and submit your app for review. Instagram has strict policy guidelines that your app needs to follow to get access. After gaining access API you can use it for free as per the rate limit. You can always upgrade your plan to match the scale of your operation. Instagram API pricing offered by Rapid API is as follows.
Model | Requests | Rate |
Basic ($0.00) | 10/day | 3 requests per minute |
Pro ($5.00/month) | 200/day | 5 requests per minute |
Ultra ($10.00/month) | 500/day | 10 requests per minute |
Mega ($100.00/month) | 6,000/day | 25 requests per minute |
Most used Instagram APIs
The most popular Instagram APIs are given below:
- Instagram Graph API
- Instagram Basic Display API
- Instagram Messaging API
- Sharing to Stories
- Embedding
Instagram graph API
The API allows you to manage your account, publish content, and access some public data from Instagram, but only a subset of features is available compared to Instagram’s official applications.
Instagram username availability API
The Instagram username availability API is a free tool that allows users to check if an Instagram name can be used. This is a great tool to businesses or individuals looking to establish their Instagram presence. The results are instantaneous
Instagram reels API
The Instagram reels API will allow developers to interact with Reels on Instagram. The API supports content publishing, insights, comment moderation, hashtag search, business discovery, mentions, promote API, and Instagram basic display API.
Instagram API get followers
Instagram API get followers is a fast way to influence you need on Instagram. The INS Followers is one of the APIs you can use to get real Instagram followers. The platform allows you to get real Instagram users.
Instagram feed API
The Instagram Basic Display API allows users of your App to get basic profile information, videos, and photos in their Instagram account. The API is used to access to any type of Instagram account.
Instagram post API
The Instagram Content Publishing API images, videos, and reels on your Instagram Business Account. The API was changed in the beginning of 2023. However Instagram Creator accounts was not supported
Instagram messenger API
Instagram messenger API offers personal connections at every phase in the marketing journey. Brands can communicate with their customers on their preferred channel. The tool allows for integration with existing tools and data and lets business manage high volume of data.
Instagram insights API
You may get information about your Instagram account, including your follower count, reach, and engagement, by using the Instagram analytics API. You may use this information to keep tabs on how well your account is performing and to plan your content strategy.
Instagram stories API
The Instagram Stories API allows you to integrate and share stories with your iOS or android apps.
Instagram ads API
Instagram share API
Instagram login API
Instagram login API allow users to log in to your account using their Instagram account. This is useful incase users want to share their Instagram stories or follow other Instagram users.
Instagram hashtag API
Inflact is an Instagram hashtag API. You can use Inflact’s Hashtag Generator to create hashtags for your social media easily. Use the data retrieved from the API to come up with countless pertinent ideas. Inflact uses the Hashtag Search functionality in the Instagram Graph API
Instagram analytics API
There are Instagram analytics API like Minter.io that provides data about Instagram performance metrics. You can use the API to create easily report using analytics data output to a variety of interfaces. Minter.io uses Insights functionality in the Instagram Graph API.
Instagram mentions API
Instagram mentions API allows you to retrieve all the mentions that users have received in comments and captions. However there are some limitations
- Mentions on stories not supported.
- Commenting on phots where you tagged are not supported.
- @mention appears was created by an account set to private.
Instagram live API
Instagram live API represents a collection of live video IG Media or an IG User. You can get a collection of live video on IG Media on an IG user. You can make requests to the API to start, stop, and manage the live video. The only limitation being only live video IG Media being broadcast at the time of the request will be returned.
Instagram images API
The Instagram Images API is a RESTful API that allows you to retrieve images from Instagram. You can use this API to get information about a specific image, such as its caption, location, and media, or you can get information about all the images from a specific user or hashtag.
Instagram demographics API
Instagram demographics API represents social media metrics on Instagram users. It allows businesses to access demographic information about their users. They can use the information to create more targeted marketing campaign.
Instagram marketing API
The Meta marketing API are a collection of Graph API endpoints that can be used to advertise on Facebook and Instagram. The Instagram marketing API can be used by businesses of all the users to reach a wider audience and improve their advertising campaigns.
Instagram download API
Instagram download API allows you to download images and captions. This is useful if you want to save photographs and captions for offline viewing or personal collections of Instagram content or sharing photos and videos. There several Instagram download API some are free and some free.
Instagram embed API
Instagram embed API allows you post your Instagram username and link to your profile along with your content or profile. Remember the account must be public and the embedded settings must be turned on. Private accounts and content cannot be embedded.
Shubha writes blogs, articles, off-page content, Google reviews, marketing email, press release, website content based on the keywords. She has written articles on tourism, horoscopes, medical conditions and procedures, SEO and digital marketing, graphic design, and technical articles. Shubha is a skilled researcher and can write plagiarism free articles with a high Grammarly score.
Leave a Reply