Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get instagram follower count from instagram public account after 2020 instagram api change?

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!

like image 959
Hyun Seok Cho Avatar asked Sep 02 '20 16:09

Hyun Seok Cho


People also ask

Does Instagram API still work?

In 2018, Instagram shut down its public API. Meaning, third-party apps can no longer access the API from Instagram without permission. Third-party apps now need to be approved by Instagram before they can access the API.

Did Instagram change their API?

Instagram announced a depreciation of the Basic Permission for its Legacy API Platform. Update: Instagram made the API change on the 29th of June, 2020 and not on the initially announced date – 2nd of March, 2020.

What information can I get from Instagram API?

The API can be used to get and publish their media, manage and reply to comments on their media, identify media where they have been @mentioned by other Instagram users, find hashtagged media, and get basic metadata and metrics about other Instagram Businesses and Creators.


3 Answers

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.

like image 69
Eehab Avatar answered Oct 06 '22 19:10

Eehab


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
like image 45
da Vinci Avatar answered Oct 06 '22 20:10

da Vinci


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

like image 2
Dyey517 Avatar answered Oct 06 '22 18:10

Dyey517