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:
Target | Supports pagination |
---|---|
instagram_graphql_user_posts | β |
instagram_graphql_profile | |
instagram_graphql_post | |
instagram_graphql_reel |
Instagram GraphQL User Posts
Returns information about a specific Instagram user.
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
target | string | β | target | instagram_graphql_user_posts |
query | string | query or user_id | Instagram user profile name | nba |
user_id | string | query or query | Unique Instagram user id | 56989304580 |
cursor | string | next page string (end_cursor value in response) | QVFBUG5LVkxEaXpPbjZ2T2dhQnVfZTdaUHdnX0VmcXNzek5IRGJTdFdQWkpqOFZDcWRTbXpZSXhkdVRoTlI3d1ExSklzay1sSW1jMkphQVROdnNXazJ6ZA== |
Using query
vs user_id
query
vs user_id
The easiest way to use the target is to provide a username as a query:
{
"target": "instagram_graphql_user_posts",
"query": "tasty"
}
However, due to Instagram's limitations, using just the query may not work on some usernames. As an escape hatch, you can also provide a user_id
to the request.
In order to get the user_id
for an account, eg tasty
(manual steps):
-
Navigate to
https://www.instagram.com/tasty
-
Open developer tools and do a global search for
"id"
in the html. A<script>
tag will be highlighted. -
Paste the
<script>
tag into a code editor and search for"id"
. The id will be nested in one of the profile objects.
This id can then be used in the scraping request:
{
"target": "instagram_graphql_user_posts",
"user_id": "56989304580" // user id for account `tasty`
}
Instagram GraphQL profile
Returns information about a specific Instagram user.
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
target | string | β | target | instagram_graphql_profile |
query | string | β | Instagram profile name | nba |
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).
Parameter | Type | Required | Description | Example |
---|---|---|---|---|
target | string | β | target | `instagram_graphql_reel |
url | string | β | Instagram reel URL | https://www.instagram.com/reel/ClfPAdQgqTc/ |
Instagram GraphQL post
Returns information from a specific Instagram post.
Parameter | Type | Required | Description | Example | |
---|---|---|---|---|---|
target | string | β | target | instagram_graphql_post | |
url | string | β | Instagram post URL | https://www.instagram.com/p/ChYHpdAvnob |
Create callback for Instagram post
POST https://scraper-api.smartproxy.com/v2/task
Payload type: JSON
Parameter | Type | Required | Description | Examples |
---|---|---|---|---|
target | string | β | target | instagram_graphql_post |
url | url | β | Instagram post URL | https://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
Updated 4 days ago