Any api end point to request user info by IG Id?

As of yesterday, https://i.instagram.com/api/v1/users/{IG Id}/info/ stopped working. Now it just returns

{“message”: “useragent mismatch”, “status”: “fail”}

even when just loading it on a regular browser (ie the error message seems to be misleading). Anyone know any other API endpoints I can use to request user info with IG Id?

Yep I noticed this too. Looking for a solution now. Please let us know if you find any. Will do the same.

Try this:
https://www.instagram.com/username/?__a=1

Use an official useragent and everything works like a charm :wink:

Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 105.0.0.11.118 (iPhone11,8; iOS 12_3_1; en_US; en-US; scale=2.00; 828x1792; 165586599)

2 Likes

That was the first thing I tried yesterday but didn’t seem to work. But now you confirmed it works, I double checked my code and realized I just didn’t put it in correctly when I tried yesterday so thank you.

2 Likes

Thanks for the response but that uses username instead of IG id. I prefer to use IG id because that’s a unique identifier where as username changes. Also you get rate limited a lot faster with that call.

Probably the best would be to keep and ID <-> USERNAME storage so you can keep blasting through the user ids and keep updating and validating your ID<->USERNAME storage.

That is at least how we are doing it. At the moment we store roughly 200 million user IDs of active (posting) accounts and that tactic saved us a lot of troubles so far.

I’m sorry–I don’t really understand. Could you please elaborate on what it means to “use an official useragent” and how this worked for you? Not really coding here or anything. I just used to be able to load https://i.instagram.com/api/v1/users/{IG Id}/info/ in my browser and access the data I needed from there. Any help is appreciated.

Yes, I save both username and IG Id save in my database. I try to use IG Id as much as possible since that’s unique identifier that can’t be changed and when my program notice the new username returned from and IG Id is not same as database, I updated the username in database. But sometimes I have to use username to open the profile with www.instagram.com/username and and when it doesn’t return a user, I make always make another request with end point that uses IG id, this way I know when if

  1. if an account is just gone for good
  2. if username is changed
  3. if the account blocked me (username will return not found but IG id would still return with the same username)

and update my database accordingly. It’s definitely good to have both in your database depending on the call you need to make.

1 Like

Useragent is an identifier for your browser type when calling the https://i.instagram.com/api/v1/users/{IG Id}/info/ (or any other http request). Try to go to https://www.whatsmyua.info with different browser you will see every browser has a different user agent. When you make that http request to IG with different browser, IG server will respond differently according to how they want to lock down their response.

About a month ago, IG had made some changes to lock down the older API end point so https://i.instagram.com/api/v1/users/{IG Id}/info/ would work on Safari fully but won’t return much information (just username but no follower/following/postCount/etc info) on Chrome anymore (probably to screw with people who use selenium chromedriver to scrape). As yesterday, they totally locked it down so that api endpoint, any browser would just return {“message”: “useragent mismatch”, “status”: “fail”} except the official one.

Lucky, you can fake user agent. You can do it manually on some browsers. Check out http://osxdaily.com/2013/01/16/change-user-agent-chrome-safari-firefox/ (I haven’t tried this route personally since I make http requests and fake user agent programmable cause I scrape thousands of profiles a day, not something that’s easy to do manually on a browser).

IG has it’s own browser, when you open a link in someone’s bio on IG app, that uses IG’s own browser. The challenge is you can’t just type in url with IG’s browser. So to find IG’s official browser’s user agent, I put https://www.whatsmyua.info in bio of one of my slaves and click on it from the API and that’s how you get the user agent info of IG’s official browser. So if you try to fake the user agent with IG official browsers, you can still get info from https://i.instagram.com/api/v1/users/{IG Id}/info/

5 Likes

Got it. Thank you so much for taking the time and explaining. This is exactly what I needed to know–I was able to change the useragent manually in my browser and it worked like a charm. I appreciate your help.

Out of curiosity, what do you scrape thousands of profiles a day for? I’m just genuinely interested to learn. Thanks again.

1 Like

Your explanation is on point except one fact. Your idea to get the agent via bio trick is good, but that’s the point why it didn’t worked for you with the api call. IG uses different user agents between their “in app browser” and their “app user agent”. The in app browser user agent never needs to call an api endpoint, so this agent is blocked too. You need the main IG app user agent sniffed thru a MITM (man in the middle attack) which is readable in all of their HTTPS api requests.

2 Likes

It helps, but now I have only
{"user": {"username": "___", "pk": ___, "profile_pic_url": "https://instagram.f___.jpg?_nc_ht=instagram.fhel4-1.fna.fbcdn.net"}, "status": "ok"}
And I am to get user’s email by PHP script.

Thanks man, it looks like it solves the problem.
:beers:

If you want full account details from this endpoint, you must log in.
This changed some time ago.

2 Likes

Of course, how could I forget that! Thanks so much for the reminder!
But now I only logged in from the browser. How am I to do this in my php script?

The easiest way is to look for a library on github.

Now I’m near to have my own library for my needs, but I only dont’ know about this tiny function.

I download all the recent posts of similar account and use an API endpoint call to download the likers and another to download the commenters but the calls only gets the username and IG id of the posts which I save in my database. So then I use https://i.instagram.com/api/v1/users/{IG Id}/info/ to grab followers/following/post counts and again save in my database. Then my bot makes sql queries to find users fitting my followers/following/post counts criteria to do actions on.

1 Like

My bio trick got the basically the same user agent you posted. I just put it for my headless browser part of my code but was using non headless browser to request the url by mistake the first time.