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

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.

can you tell me the end point to get users recent posts? i am trying to do the same too

Got it. Thank you.

If you only care about the most recent (12) posts, https://www.instagram.com/{username}/?__a=1 will do. In the JSON under [‘graphql’][‘user’][‘edge_owner_to_timeline_media’][‘edges’] will give you the last 12 posts’ info then you loop through them to get [‘node’][‘shortcode’]. https://www.instagram.com/p/[shortcode] will be the url of each post.

If you want more than 12, it will be slightly more complicated. You need to look at [‘graphql’][‘user’][‘edge_owner_to_timeline_media’][‘page_info’][‘end_cursor’] and add that end_cursor to the original end point url

https://www.instagram.com/{username}/?__a=1&after={end_cursor} which will return another 12 and give you another end cursor to request the next 12

3 Likes

We were discussing doing this but in a much more complicated way in a recent thread! Are there more threads to learn more about how to do this? Right now I don’t really understand everything said here.

I need to convert a txt file of user ids to usernames
how to do it?

You have to query with the appropriate user agent, you can do it even from the browser by setting it with the appropriate extension.

If you want to do it on a larger scale, you will need to do it through multiple IP addresses.

1 Like

thank you @jakim. but how do I click on the link from the API?

UserAgent was given in this thread, use it.