Instagram

The Social Media Scraping API allows you to scrape information from Instagram. The API uses GraphQL targets which return data in JSON.

πŸ“˜

While the targets in this page use GraphQL under the hood, they are interfaced with via REST.

The following GraphQL targets are available:

Endpoint

POST https://scraper-api.smartproxy.com/v2/scrape

Instagram GraphQL profile

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_profile
usernamestringβœ…Instagram profile namenba
localestringlanguage locale
geostringgeolocation

Return value JSON:

  • Basic information (name, description, follower count).
  • 25 most recent posts.

Examples

{
    "target": "instagram_graphql_profile",
    "username": "nba"
}
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"username\": \"nba\", \"target\": \"instagram_graphql_profile\",\"locale\": \"en-us\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/nba',
  	'target': 'instagram_graphql_profile',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/nba',
  	'target' => 'instagram_graphql_profile',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL User Posts

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_user_posts
usernamestringβœ…Instagram user profile name.nba
localestringlanguage locale
countstringpost count: min 12, max 50 per response50
cursorstringnext page string (end_cursor value in response)QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA
geostringgeolocation

Return value JSON:

  • Basic information (name, description, follower count).
  • Up to 50 most recent posts. Amount can be specified with count parameter.

Examples

curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"username\": \"nba\", \"target\": \"instagram_graphql_user_posts\",\"locale\": \"en-us\", \"cursor\": \"QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA\", \"count\": \"50\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'username': 'nba',
  	'target': 'instagram_graphql_user_posts',
  	'locale': 'en-us',
  	'count': '50',
  	'cursor':'QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'username' => 'nba',
  	'target' => 'instagram_graphql_user_posts',
  	'count' => '50',
  	'locale' => 'en-us',
  	'cursor' => 'QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL User Following

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_user_following
usernamestringβœ…Instagram profile usernamenba

Return value:

  • JSON containing the number of profiles this user is following (no exact profile names).

Instagram GraphQL User Followers

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_user_followers
usernamestringβœ…Instagram profile usernamenba

Return value:

  • JSON containing the number of followers this user has (no exact follower handles).

Instagram GraphQL post

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_post
urlstringβœ…Instagram post URLhttps://www.instagram.com/p/ChYHpdAvnob
localestringlanguage locale
geostringgeolocation

Return value JSON:

  • Basic information (post description, likes, comment count, author, related posts).
  • The top 10 comments (Instagram sorts these by its own ranking).

Examples

{
    "target": "instagram_graphql_post",
    "query": "tasty"
}
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"url\": \"https://www.instagram.com/p/ChYHpdAvnob", \"target\": \"instagram_graphql_post\",\"locale\": \"en-us\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/p/ChYHpdAvnob',
  	'target': 'instagram_graphql_post',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/p/ChYHpdAvnob',
  	'target' => 'instagram_graphql_post',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL hashtag

πŸ“˜

Note that there are two separate hashtag-related targets:

  • instagram_graphql_hashtag
  • instagram_graphql_hashtags

Both return similar hashtag information, but share a different data format. If one target does not fit your use case, the other target can be used.

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_hashtags
querystringβœ…
localestring
geostring

Examples

{
    "target": "instagram_graphql_hashtag",
    "query": "tasty"
}
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"url\": \"https://www.instagram.com/explore/tags/nba/\", \"target\": \"instagram_graphql_hashtag\",\"locale\": \"en-us\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/explore/tags/nba/',
  	'target': 'instagram_graphql_hashtag',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/explore/tags/nba/',
  	'target' => 'instagram_graphql_hashtag',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Instagram GraphQL Hashtags

POST https://scraper-api.smartproxy.com/v2/scrape

Return value JSON:

  • Basic information (description, shortcodes, image URLs, like count, comment count).
  • Up to 155 most recent posts. Amount can be specified with count parameter.

Payload type: JSON

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_hashtags
querystringβœ…Instagram hashtagpizza
localestringlanguage locale
countstringpost count: min 12, max 50 per response50
cursorstringnext page string (end_cursor value in response)QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw
geostringgeolocation
curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/scrape -H "Content-Type: application/json" -d "{\"query\": \"pizza\", \"target\": \"instagram_graphql_hashtags\",\"locale\": \"en-us\", \"cursor\": \"QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw\", \"count\": \"50\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'query': 'pizza',
  	'target': 'instagram_graphql_hashtags',
  	'locale': 'en-us',
  	'count': '50',
  	'cursor':'QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/scrape',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'query' => 'pizza',
  	'target' => 'instagram_graphql_hashtags',
  	'count' => '50',
  	'locale' => 'en-us',
  	'cursor' => 'QVFCOGRkYjNfM0xOUlg2T1c1ZzhhemFGQ3RVSjg3Sm5Jb0lUenhPYmxqQWRZbzNWUEdNNjBKZ2hlT2RXTF9BVS1PQW1PZkxscXNaOS1qNk5YUXFBWUVWUw',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/scrape');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Create callback for Instagram post

  POST https://scraper-api.smartproxy.com/v2/task

Payload type: JSON

ParameterTypeRequiredDescriptionExamples
targetstringβœ…targetinstagram_graphql_post
urlurlβœ…Instagram post URLhttps://www.instagram.com/p/ChYHpdAvnob
localestringlanguage locale
geostringgeolocation

curl -u username:password -X POST --url https://scraper-api.smartproxy.com/v2/task -H "Content-Type: application/json" -d "{\"url\": \"https://www.instagram.com/p/ChYHpdAvnob/\", \"target\": \"instagram_graphql_post\",\"locale\": \"en-us\",\"geo\": \"United States\" }"
import requests

headers = {
    'Content-Type': 'application/json'
}

task_params = {
    'url': 'https://www.instagram.com/p/ChYHpdAvnob/',
  	'target': 'instagram_graphql_post',
  	'locale': 'en-us',
  	'geo': 'United States'
}

username = 'username'
password = 'password'
  
response = requests.post(
    'https://scraper-api.smartproxy.com/v2/task',
    headers = headers,
    json = task_params,
    auth = (username, password)
)
print(response.text)
<?php

$params = array(
    'url' => 'https://www.instagram.com/p/ChYHpdAvnob/',
  	'target' => 'instagram_graphql_post',
  	'locale' => 'en-us',
  	'geo' => 'United States'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://scraper-api.smartproxy.com/v2/task');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>

Pagination for Posts & Hashtags

Pagination is supported for instagram_graphql_hashtags & instagram_graphql_user_posts targets. First response returns pagination information - existence of multiple pages & end cursor of the current page. Providing this cursor value with a subsequent request will fetch the following page.

Retrieve parsed results via callback

GET https://scraper-api.smartproxy.com/v2/task/{Task_ID}/results?type=parsed

Retrieve raw HTML results via callback

GET https://scraper-api.smartproxy.com/v2/task/{Task_ID}/results?type=raw