AI Tools

Instagram Graph API Setup Guide: Complete Step-by-Step Tutorial for Developers 2025

Fardin Alam12 min read

The Instagram Graph API is the official way to pull Instagram data into your own app, and every serious analytics dashboard, scheduler or engagement tracker is built on it. The insights inside the Instagram app only go so far, and you only get them on business accounts. If you want custom reports, or a tool you can sell to creators (people who care a lot about growing on social media), you need the API.

In this tutorial we go from an empty folder to a working Node.js app that logs a user in and reads their profile. Meta changes some of these details often, so in those places I’ll send you to the docs, since anything I copy here can go out of date.

Prerequisites checklist

• Basic JavaScript, HTML and CSS, plus general web development concepts

• Comfort with a terminal (Terminal on Mac or Linux, CMD on Windows)

• An Instagram Business or Creator account (personal accounts can’t use the API)

• A Facebook developer account for your API credentials

• Patience to read the Meta documentation properly

The cost is mostly your time. You can build all of this with free or cheap services, and the API itself is free within reasonable limits, although a large production app may run into costs.

Instagram Graph API setup tutorial in five phases

How the Instagram Graph API fits together

The Instagram Graph API is a REST interface that lives inside the Meta developer platform. Your app never talks to Instagram on its own. Every request goes through the Facebook Graph API infrastructure, and that layer exposes Instagram data through standard endpoints.

Login runs on OAuth 2.0. The user approves your app first, and after that it can read only the specific data they allowed. Users stay in charge of their own privacy this way, and developers can still build on it.

The build has five phases: API setup, local environment, back end, front end and testing, then deployment. If you’ve built web apps before, plan on roughly 8 to 12 hours in total.

Phase 1: Instagram Graph API setup in the Meta dashboard

Step 1: Create a developer account for the Instagram Graph API

Go to developers.facebook.com. You’ll need a Facebook account first, and registration includes identity verification as part of the Meta developer approval process.

Meta will ask what you plan to build, and it helps to be specific. Saying you’re making Instagram analytics or creator tools is a perfectly fine answer. Meta supports legitimate developer apps, so it won’t trigger restrictions.

Step 2: Create a new app

In the dashboard, click Create App, give it a name and a contact email, then choose the use case called Manage messaging & content on Instagram. Connecting a business portfolio is optional while you test. Once the app exists, write down three things:

  • Your Instagram App ID is under API setup with Instagram login, in Business login settings. The login flow uses this one, and it isn’t the same as the Meta App ID shown at the top of the dashboard.
  • The Instagram App Secret sits right next to it. Keep it private and never commit it to version control.
  • Note the API version too. The official examples use v26.0 as of October 2026, but use whatever the current stable release is when you build.

Step 3: Add the Instagram Graph API product

Open your use case and go to API setup with Instagram login. Add the Instagram professional account you want to test with (Business or Creator), then open Business login settings under Set up Instagram business login. Your Instagram App ID, App Secret and OAuth redirect URIs all live there. If you’re still on a personal account, switch it first in the Instagram app under Settings, then Account type and tools, then Switch to professional account.

Treat your App ID and App Secret like passwords. Every authenticated call your app makes depends on them.

Step 4: Set your OAuth redirect URIs

OAuth needs to know where to send users after they approve your app, so add two redirect URIs in the app settings, one for development and one for production:

  • Development: http://localhost:3000/auth/callback
  • Production: https://yourdomain.com/auth/callback

They have to match exactly. Even a trailing slash counts as a difference.

Phase 2: Set up your local environment

Step 5: Install Node.js and npm

Download Node.js from nodejs.org. npm (the Node package manager) comes bundled with it. Open a terminal and check that both are installed:

node --version
npm --version

Each command should print a version number. Don’t start on the Instagram Graph API code until both do.

For example, here is what that looked like on my machine on 28 October 2026. Your numbers will differ, and any recent long-term support release of Node.js is fine.

Terminal showing node --version and npm --version output
Both commands print a version number, so you’re ready.

Step 6: Create the project and install packages

Make a project folder, create package.json (it keeps track of your dependencies) and install Express, Axios, dotenv and CORS:

mkdir instagram-analytics-tool
cd instagram-analytics-tool
npm init -y
npm install express axios dotenv cors

Usually the install takes a few seconds. Today it pulls in Express 5, and all the code below was tested against that version.

Terminal output of npm install for express, axios, dotenv and cors
A clean install with 0 vulnerabilities.

Step 7: Keep credentials in a .env file

Create a .env file in the project root to hold your Instagram Graph API credentials:

APP_ID=your_app_id_here
APP_SECRET=your_app_secret_here
REDIRECT_URI=http://localhost:3000/auth/callback
PORT=3000

Add .env to your .gitignore straight away. Pushing secrets to GitHub or any public repo is a serious security hole, and nobody else should ever see your App Secret.

Phase 3: Build the Instagram Graph API back end

Step 8: Write the Express server

Create server.js. This file handles the OAuth flow. When someone visits /auth/instagram, the server sends them to Instagram to grant access. Instagram then returns them to /auth/callback with a code, and your server swaps that code for an access token. The express.static line also serves the page you’ll build in Step 10, so there’s something to see at http://localhost:3000.

const express = require('express');
const axios = require('axios');
require('dotenv').config();
const cors = require('cors');

const app = express();
app.use(express.json());
app.use(cors());
app.use(express.static('public')); // serves public/index.html at http://localhost:3000

// Step 1: send the user to Instagram to approve access
app.get('/auth/instagram', (req, res) => {
  const authURL = 'https://www.instagram.com/oauth/authorize'
    + '?client_id=' + process.env.APP_ID
    + '&redirect_uri=' + encodeURIComponent(process.env.REDIRECT_URI)
    + '&response_type=code'
    + '&scope=instagram_business_basic';
  res.redirect(authURL);
});

// Step 2: swap the returned code for a short-lived access token
app.get('/auth/callback', async (req, res) => {
  const { code } = req.query;
  try {
    const tokenResponse = await axios.post(
      'https://api.instagram.com/oauth/access_token',
      new URLSearchParams({
        client_id: process.env.APP_ID,
        client_secret: process.env.APP_SECRET,
        grant_type: 'authorization_code',
        redirect_uri: process.env.REDIRECT_URI,
        code: code
      })
    );
    const body = tokenResponse.data;
    const accessToken = body.access_token || (body.data && body.data[0].access_token);
    // Store the token server-side (session or database) in a real app
    res.redirect('/dashboard');
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log('Server running on port ' + PORT));

Before publishing, I ran this exact file on 28 October 2026. It uses Business Login for Instagram, which replaced the old Basic Display API after Meta shut that down in December 2024. So the login page is www.instagram.com/oauth/authorize, the scope is instagram_business_basic, and the code exchange is a form POST to api.instagram.com/oauth/access_token. Meta does change these from time to time, so compare them with the official docs before you ship, and keep tokens on the server instead of passing them around in URLs.

Instagram Graph API docs page for Business Login listing the instagram_business scope values
The Business Login docs from Meta, with the current scope names.

Step 9: Read profile data with the Instagram Graph API

With a token in hand you can fetch real data. This route reads basic profile fields, which is where any analytics tool starts:

app.get('/api/user/profile', async (req, res) => {
  const accessToken = getTokenForUser(req); // read it from your session or database
  try {
    const response = await axios.get('https://graph.instagram.com/v26.0/me', {
      params: {
        fields: 'user_id,username,name,profile_picture_url,followers_count,media_count',
        access_token: accessToken
      }
    });
    res.json(response.data);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

Phase 4: Front end and local testing

Step 10: Create a simple page

Add public/index.html with a basic page layout and put a single connect button inside the body:

<div class='container'>
  <p>Connect your Instagram account to view analytics</p>
  <button onclick='location.href="/auth/instagram"'>Connect Instagram Account</button>
</div>

Step 11: Test on localhost

Start the server and test the Instagram Graph API login locally:

node server.js

Also, recent versions of dotenv print a line saying how many variables they loaded. If it says 4, your .env file was read correctly.

Terminal showing node server.js running on port 3000
The server is up and the .env values loaded.

Open http://localhost:3000. You should see the line of text and the button from Step 10.

Instagram Graph API local test page with a Connect Instagram Account button
The page at localhost:3000. Plain, but it works.

Next, click the button. If Instagram shows “Page isn’t available”, the client ID in the URL is wrong. That’s exactly what I got while my .env file still had the placeholder app ID. With your real Instagram App ID and a redirect URI that matches the dashboard, you get the Instagram login and permission screen instead.

Instagram Page isn't available screen shown for an invalid client ID
What you see when the App ID is still a placeholder.

After you approve, Instagram sends you back to /auth/callback. The callback then redirects to /dashboard, which you haven’t built yet, so “Cannot GET /dashboard” at that point means the login itself worked. Log the token on the server once to confirm, then build that page.

Phase 5: Deploy your Instagram Graph API app

Step 12: Pick hosting and go live

Plenty of hosts can run an Instagram Graph API app built on Node.js. Hostinger, for one, has plans with Node.js support starting at around ₹300 a month. Once you’ve bought hosting:

  1. Upload your project files through the File Manager.
  2. Set up the Node.js application in cPanel.
  3. Change REDIRECT_URI in .env to your live domain.
  4. Update the redirect URIs in the Meta developer dashboard so they match.

Then visit your domain and go through the whole login flow to make sure everything works.

Troubleshooting common Instagram Graph API errors

ProblemLikely causeFix
“Redirect URI mismatch”The URI in .env differs from the dashboard, even by a slashCopy the exact same string into both places
No API access for the accountIt’s a personal Instagram accountSwitch to a Business or Creator account
Sudden failures under loadYou hit rate limitsCheck the limits for your app tier and queue requests
Login works locally but not liveProduction URI not added in the dashboardAdd the live callback URL and update .env
Random crashes on requestsNo error handling for failed callsWrap every request and log the errors

Most of these come down to a few habits. Never commit credentials, since keeping them in .env with .gitignore is the most important safety step in this whole guide. Read the rate limits before launch, because apps that ignore them fail suddenly in production. And assume things will break. Networks drop, endpoints change and quotas run out, so wrap every request in proper error handling and log what fails.

Instagram Graph API security and privacy basics

  • Protect access tokens, since anyone holding one has programmatic access to that user’s account. Keep them out of the browser console, logs and version control, and only send them over HTTPS.
  • Look up the rate limits for your tier in the docs, then queue requests so a busy period doesn’t break the app.
  • If you store user data, follow local privacy laws (GDPR in Europe, CCPA in California and so on) and publish a clear privacy policy that explains what you collect and why.

Instagram Graph API time and difficulty

PhaseTimeDifficulty
API setup1 to 2 hoursEasy
Environment and dependencies30 minutesEasy
Back-end development3 to 4 hoursMedium
Front-end and testing2 to 3 hoursMedium
Deployment1 to 2 hoursMedium
Total8 to 12 hoursIntermediate

Once your tool works, the next job is helping the creators who use it grow. My guides on social media growth in 2026 and why Reels stop getting views will give you a feel for what your users care about. For full endpoint references and the current rate-limit rules, keep the official Instagram Graph API documentation open while you build.


Before launch, run one last check: credentials in .env with Git ignoring them, identical redirect URIs in your code and in the dashboard, error handling and logging in place, monitoring for API errors, and documentation for your own app. If all five hold, you’re ready to ship.

This guide reflects common Instagram Graph API practices at the time of writing. Versions, scopes and features change often, so check the current Meta documentation before you deploy to production.

Share:

Fardin Alam

AI enthusiast, entrepreneur, and content creator sharing AI tools, online income strategies, business ideas, and finance insights.

Leave a comment

Your email address will not be published. Required fields are marked *

Stay In The Loop

Let’s Stay Connected

New guides every week. Follow along on social, or go deeper with the course.