24

I am trying to retrieve the follower count only just using a user's instagram handle (aka @myusername). I read in several answers that you can access the "https://www.instagram.com/{username}/?__a=1" to retrieve the block of json that has all the details. However, when I try to do that now in 2020 after the api change, the url simply redirects me to the login page.

I also looked at instagram basic display/graph api but I can't seem to find a way to get other users' follower counts.

From the official ig basic display api documentation: https://developers.facebook.com/docs/instagram-basic-display-api/reference/user
This api only allows you to get the account_type, id, ig_id (about to be deprecated), media count and username. (no sign of follower count)

From the official ig graph api documentation: https://developers.facebook.com/docs/instagram-api
"The API cannot access Intagram consumer accounts (i.e., non-Business or non-Creator Instagram accounts). If you are building an app for consumer users, use the Instagram Basic Display API instead."

Since my program is suppose to retrieve the follower count from accounts that are not necessarily professional, I can't seem to figure out what to do...

In conclusion:

  • I have tried web scraping -> get redirected to login page
  • Basic display api -> can't get the follower count
  • Graph api -> can't access consumer accounts

Does anyone have a solution for this?

Thank you!

Hyun Seok Cho
  • 341
  • 1
  • 2
  • 3

3 Answers3

11

Had the same problem. I ended up inspecting instagram network and found this:

https://i.instagram.com/api/v1/users/web_profile_info/?username=<USERNAME>.

Make sure you put a user-agent header in the request with this value:

Instagram 76.0.0.15.395 Android (24/7.0; 640dpi; 1440x2560; samsung; SM-G930F; herolte; samsungexynos8890; en_US; 138226743)

you can get the follower count on data.user.edge_followed_by.count

Dyey517
  • 426
  • 5
  • 15
5

You can use Instaloader Python module. Here is a quic example:

import instaloader
L = instaloader.Instaloader()
user = "IG_USERNAME"
password = "IG_PASSWORD"
L.login(user, password)
profile = instaloader.Profile.from_username(L.context, user)

print(profile.followees) #number of following
print(profile.followers) #number of followers
print(profile.full_name) #full name
print(profile.biography) #bio
print(profile.profile_pic_url)  #profile picture url 
print(profile.get_posts()) #list of posts
print(profile.get_followers()) #list of followers
print(profile.get_followees()) #list of followees
da Vinci
  • 131
  • 11
4

Instagram blocked your IP ... you need to use undetected proxies to scrape that from Instagram, usually, Residential IPs passed.

send HTTP request to IG API end > if got JSON response it's good and not detected, else it's detected proxy and not good for Instagram.

code for that (in c# but could follow the same logic in python) :

var httpClientHandler = new HttpClientHandler()
            {
                Proxy = new WebProxy("127.0.0.1:8080", false),
                UseProxy = true
            };

            var client = new HttpClient(handler: httpClientHandler, disposeHandler: true);
            var response = await client.GetAsync("https://www.instagram.com/instagram/?__a=1");

        
            if ( response.Content.Headers.ContentType.MediaType == "application/json")
            {
                // Not detected proxy and good for Instagram

            }
            else
            {
               // Detected proxy and not good for Instagram
            }

If you ask why Instagram is blocking some IPs? simply Instagram has a huge database that contains past IPs who sent more than the allowed limit requests ... they are doing that to prevent scraping.

Eehab
  • 154
  • 1
  • 5