Instagram Public Api ( __a=1 ) is banned. Any alternative?

Viewed 11262

I used instagram public api (adding __a=1 to parameters of an url) to get a post detail (caption ,imageUrl, postType, likes, comments , viewsCount). But it seems that Instagram banned that recently and returned a 403. It also asks for login when I try to directly open a post by its usrl.

I tried to use the instagram private api (https://mgp25.github.io/) for getting post details, but after some requests instargam banned that too:

"throttled by instagram because of too many api requests"

Do you have any offer for an alternative?

4 Answers

Actually it is not really banned but now redirects with 302 to auth page. It seems like auth is required when Instagram account and query geoIPs are different. Alternative is to use official API. No scraping can be done, because the profile link now also requires authentication. You can do authenticated scraping but you are limited to 200 queries ( that Instagram sends to get data) per hour.

Instagram blocked all public endpoints with some limitations and hit rate. Now you need to send the user's session to get the response.

Did you notice the same endpoint returning the JSON response when you are logged in on Instagram in the same browser? Yes, that because whenever you are hitting the URL like "https://www.instagram.com/anything/?__a=1", your browser sending the live and valid sessionid to Instagram. Since you are logged in hence Instagram served you well.

Ever you wonder why the same endpoint started to work again after changing the Internet connection from Wifi to Mobile hotspot or try with another internet service provider.

It's because your IP got blocked and no more free hot babes for you until you are logged in.

Below is the PHP code to give a try with sessionid.

<?php
// keyword or user name
$hashtag = $username = "msevylynch";
// $endpoint = "explore/tags/$hashtag"; // hashtag search
$endpoint = $username; // user search
// login in insta account and copy session from browser's cookie tab
$sessionid = '<YOU-SESSION-ID-PICK-FROM-BROWSER-AFTER-LOGIN>';

$ch = curl_init();
https://www.instagram.com/explore/tags/msevylynch/?__a=1
curl_setopt($ch, CURLOPT_URL, "https://www.instagram.com/{$endpoint}/?__a=1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Cookie: ds_user='.$username.'; igfl='.$username .'; sessionid=' . $sessionid,
    'User-Agent: Instagram 7.16.0 Android'
));
$response = curl_exec($ch);

header('Content-Type: application/json');
echo $response;
?>

Still no luck then it means Instagram blocked you or your IP for some time due to

  1. hitting endpoint too early or very fast programmatically
  2. denied the presented challenge
  3. seems it's an automated hit
  4. password is changed
  5. you are logged out
  6. or your internet bill is over due .. ha ha ha

Thank you for the reading this long, much apriceated.

Instagram is getting very strict with __a=1 endpoint. Your best bet in 2021 to get Instagram profile info is to use clean residential proxies

They require residential IPs to access ?__a=1 pages without login. https://webscraping.ai works for it if you use proxy=residential parameter. An example of such a request:

curl "https://api.webscraping.ai/html?api_key=test-api-key&proxy=residential&url=https%3A%2F%2Fwww.instagram.com%2Finstagram%2F%3F__a%3D1"
Related