Instagram Data API
Welcome to the Instagram Data API! This tutorial will guide you through using this API to fetch public Instagram user information and post data. Whether you want to display the latest posts on your website or perform social media analysis, this guide will provide you with clear instructions.
1. Core API Features
This API provides two core functions:
- Get User Info and Recent Posts: Fetch a user's public information (like follower count, following count, bio) and a list of their recent posts by using their
username
orprofile URL
. - Get Specific Media Data: Fetch detailed information for a single post (Post or Reel), primarily the direct link to the media file, by using the post's
code
orpost URL
.
2. Getting Started
Before you begin, you only need one thing:
- API Key (
apikey
): This is your unique authentication token. Please make sure you have obtained a valid API Key from juheapi.com. You will need to include this key in all your API requests.
3. Endpoints Explained
3.1 Get User Info (/instagram/v1/user_info
)
This endpoint is your entry point for retrieving overall user information.
Function: To query the public profile and recent posts of a specific user.
Method: GET
URL: https://hub.juheapi.com/instagram/v1/user_info
Parameters:
Parameter | Type | Required | Description |
---|---|---|---|
apikey | string | Yes | Your API Key |
username_or_url | string | Yes | The target user's Instagram username or full profile URL |
Request Example (using cURL):
Let's say you want to query the user nasa
:
curl "https://hub.juheapi.com/instagram/v1/user_info?apikey=YOUR_API_KEY&username_or_url=nasa"
Please replace YOUR_API_KEY
with your own API Key.
Successful Response Breakdown:
Upon a successful request, you will receive a JSON object with the following main structure:
{
"code": "0",
"msg": "success",
"data": {
"user_data": {
"follower_count": 96800000,
"following_count": 81,
"media_count": 4035,
"full_name": "NASA",
"username": "nasa",
"is_verified": true,
"profile_pic_url": "...",
"is_private": false
},
"user_posts": [
{
"node": {
"code": "C9xY5ZgR3jB",
"image_versions2": {
"candidates": [
{
"url": "https://.../image.heic"
}
]
},
"id": "333..."
}
},
// ... more posts
]
}
}
data.user_data
: Contains the core user statistics.follower_count
: Number of followers.media_count
: Total number of posts.full_name
: The user's full name.username
: The user's username.
data.user_posts
: This is an array containing the user's recent posts.node.code
: Very important. This is the unique shortcode for each post, which can be used to query for individual post details.node.image_versions2.candidates[0].url
: The URL for the post's image/thumbnail.
3.2 Get Media Data (/instagram/v1/media_data
)
Use this endpoint when you want to get detailed information about a specific post.
Function: To query the media information for a single Post or Reel.
Method: GET
URL: https://hub.juheapi.com/instagram/v1/media_data
Parameters:
Parameter | Type | Required | Description |
---|---|---|---|
apikey | string | Yes | Your API Key |
reel_post_code_or_url | string | Yes | The post's unique code (from the previous API call) or the full post URL |
type | string | Yes | The media type, post or reel |
Request Example (using cURL):
Using the post code
"C9xY5ZgR3jB" obtained from the previous step:
curl "https://hub.juheapi.com/instagram/v1/media_data?apikey=YOUR_API_KEY&reel_post_code_or_url=C9xY5ZgR3jB&type=post"
Successful Response Breakdown:
The response will provide details for the media file, most importantly the media URL.
{
"code": "0",
"msg": "success",
"data": {
"id": "333...",
"code": "C9xY5ZgR3jB",
"image_versions2": {
"candidates": [
{
"url": "https://.../image.heic",
"height": 1080,
"width": 1080
}
]
}
// For a video (Reel), there will also be a video_versions field here
}
}
4. Practical Example: Display the Latest 3 Posts on a Website
This is a common use case. Let's see how to implement it in two steps.
Step 1: Get the User's Recent Post List
First, call the /user_info
endpoint to get the user's data.
// Pseudo-code example
async function getLatestPosts(username) {
const apiKey = 'YOUR_API_KEY';
const url = `https://hub.juheapi.com/instagram/v1/user_info?apikey=${apiKey}&username_or_url=${username}`;
const response = await fetch(url);
const data = await response.json();
if (data.code === "0") {
// Slice the array to get the 3 most recent posts
return data.data.user_posts.slice(0, 3);
} else {
console.error("API Error:", data.msg);
return [];
}
}
Step 2: Render the Posts on Your Webpage
Once you have the array of posts, you can loop through it, extract the image links, and display them on your site.
// Pseudo-code example
async function displayPosts() {
const posts = await getLatestPosts('nasa');
const gallery = document.getElementById('instagram-gallery');
posts.forEach(post => {
const imageUrl = post.node.image_versions2.candidates[0].url;
const postUrl = `https://www.instagram.com/p/${post.node.code}/`;
const link = document.createElement('a');
link.href = postUrl;
link.target = '_blank';
const img = document.createElement('img');
img.src = imageUrl;
link.appendChild(img);
gallery.appendChild(link);
});
}
displayPosts();
With these steps, you can easily integrate the latest content from any public Instagram account into your application.
5. Error Handling
When a request fails, the API will return a non-"0" code
and a corresponding error message msg
.
code: "10001"
: Usually indicates an invalid parameter, such as an incorrectusername_or_url
.code: "20001"
: Indicates an error with the upstream service. You can try again after a short delay.
Check the msg
field in the response to help you quickly diagnose the problem.
Happy coding!