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:

Instagram GraphQL User Posts

Returns information about a specific Instagram user.

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_user_posts
querystringβœ…Instagram user profile name.nba
countstringpost count: min 12, max 24 per response24
cursorstringnext page string (end_cursor value in response)QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA==

Return value JSON:

  • Basic information (name, description, follower count).

Instagram GraphQL profile

Returns information about a specific Instagram user.

ParameterTypeRequiredDescriptionExample
targetstringβœ…targetinstagram_graphql_profile
querystringβœ…Instagram profile namenba

Return value JSON:

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

Instagram GraphQL Reel

Returns the number of profiles this user is following (no exact profile handles).

ParameterTypeRequiredDescriptionExample
targetstringβœ…target`instagram_graphql_reel
urlstringβœ…Instagram reel URLhttps://www.instagram.com/reel/ClfPAdQgqTc/

Instagram GraphQL post

Returns information from a specific Instagram post.

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

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

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