143

I'm in the process of embedding my image feed in my website using JSON, the URL needs my user id so I can retrieve this feed.

So, where can I find/get my user id?

Braiam
  • 1
  • 11
  • 47
  • 78
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
  • 1
    I've found a new and faster tool for this, see https://www.codeofaninja.com/tools/find-instagram-user-id – Emkey Apr 17 '17 at 12:32
  • You may also be interested in finding the username from a user ID, in case someone changes frequently the username. I added an answer that works without access token: https://stackoverflow.com/a/60744028/1176454 – baptx Mar 18 '20 at 16:53
  • This tool is my favorite to find instagram user id: https://www.thekeygram.com/find-instagram-user-id/ – Cpu Nerd Dec 11 '20 at 05:12

29 Answers29

286

Update in Jun-5-2022, Instagram API no longer use Bearer Token for authentication. But I find another useful API. All you need is added extra header X-IG-App-ID with "magic value".

https://i.instagram.com/api/v1/users/web_profile_info/?username=therock

Use can use my docker container Insta-Proxy-Server to bypass the authentication.

https://hub.docker.com/repository/docker/dockerer123456/insta-proxy-server

Demo video (I just run directly from source code): https://www.youtube.com/watch?v=frHC1jOfK1k


Update in Mar-19-2022, the API is require login now. Sorry for the bad news.

But we can solve this problem in two ways.

  1. Using my C# lib, login using your account (without any Instagram app token stuff and graph api.)
  2. In case the lib failed (I'm no longer maintain it long time ago), create a proxy server with logged in instagram account.

[Your app] --> [Proxy server] --> [Instagram] --> [Proxy server] -(forward)-> [Your app]

For Proxy server, you can use Nodejs app which install Chromium headless module (Puppeteer for example), logged in with an instagram account.

Proof of concept:

https://www.youtube.com/watch?v=ZlnNBpCXQM8

https://www.youtube.com/watch?v=eMb9us2hH3w


Update in June-20-2019, the API is public now. No authentication required.


Update in December-11-2018, I needed to confirm that this endpoint still work.

You need to login before sending request to this site because it's not public endpoint anymore.


Update in Apr-17-2018, it's look like this endpoint still working (but its not public endpoint anymore), you must send a request with extra information to that endpoint. (Press F12 to open developer toolbar, then click to Network Tab and trace the request.)


Update in Apr-12-2018, cameronjonesweb said that this endpoint doesn't work anymore. When he/she trying to access this endpoint, 403 status code return.


You can get user info when a request is made with the url below:

https://www.instagram.com/{username}/?__a=1

E.g:

This url will get all information about a user whose username is therock

https://www.instagram.com/therock/?__a=1
Thinh Vu
  • 3,036
  • 1
  • 12
  • 8
  • 2
    How did you find it? – nilfalse Aug 22 '16 at 19:22
  • 7
    When you open Developer Windows of your browser and open Network tab, you can see request to this url. – Thinh Vu Sep 04 '16 at 10:57
  • 3
    look for the owner id. – Gulok Sep 22 '16 at 04:23
  • 1
    this is awesome! nice find. let's hope this doesn't get rate limited. – ded Nov 03 '16 at 06:01
  • 1
    how to paginate results using this approach? – mpr Feb 11 '17 at 20:40
  • What the hack is this approach? I mean, I spent a lot of time today setting up sandbox user etc while I could just do a simple request by username? Thank you for the solution! – Desprit Mar 30 '17 at 01:57
  • this works! this even returns the user's media list. hell yea! the current accepted answer does not work. – RZKY Jun 20 '17 at 11:14
  • WOW, I'ts completely public endpoint! I've spent half day to figure out, how to get access token and pass authentication, just to get recent media of a user. This is a simplest, one second solution! – AntonAL Feb 19 '18 at 14:41
  • is there any way to get same detail in case of username is changed? – Kuldeep Apr 10 '18 at 07:29
  • Hi @ThinhVu, Some time it's not respond anything. And it happens for many days. *403 Forbidden error.* – Ayaz Rafai Jun 26 '18 at 10:45
  • 2
    Unfortunately, this doesn't work unless you have a specific user ID that you know. The way instagram check if its a valid request is by the cookie submitted in the header. If user_id exist in the cookie proeprty, it'll be considered a valid request. Check out the cookie property on the request header when you navigate to the URL shown – Kiong Jul 06 '18 at 15:52
  • this give me 403 without login into instagram – SAURABH RATHOD Dec 09 '18 at 18:45
  • @SAURABHRATHOD You need to modify request header a bit. I don't know exactly what you need to modify. When i changed few header field value and test this endpoint on December 11 2018, it still work. https://youtu.be/ec5QhwM6fvc – Thinh Vu Dec 11 '18 at 14:02
  • 1
    It's working now without any modification to the request. I'm logged in tho. – yukashima huksay Jun 08 '19 at 03:28
  • You should mention the source also (how you found it): this API endpoint is used when you click on a user profile with Instagram web version. – baptx Sep 14 '19 at 10:35
  • https://www.instagram.com/{username}/?__a=1 appears to be rate limited. Is there a work around to it? – Sarfraz Mar 10 '20 at 18:45
  • Really cool solution! Unfortunately, just announced in the [03/30/2020 update](https://www.instagram.com/developer/), this Legacy API is planned for deprecated by June 29, 202. I sure hope I'm wrong! The "Instagram Basic Display API" is a total pain compared to this. (you'll understand when you try to create "Instagram Test Users"...all those accounts have to be user accounts YOU own or have credentials to). It's clear that the company is taking extreme (maybe too extreme?) measures around privacy. – RichS May 08 '20 at 08:08
  • Also, fwiw...it appears that Instagram makes use of your browser's IndexedDB to cache the usernames / userId pairs of all users that you follow. You can see the pairs in dev tools. Application --> IndexedDB --> Redux --> Paths --> "users.usernameToId" – RichS May 08 '20 at 08:45
  • @Thinh Vu How can I get the username from a user_id? – wanghaoming May 27 '21 at 07:53
  • This endpoint seems to be heavily IP-based rate limited. Did anyone found a workaround around that? – Théo Champion Jun 01 '21 at 09:51
  • this is limited as you can't use this in production mode due to CORS error. – Dastan Aug 05 '21 at 12:02
  • @Pengin https://www.npmjs.com/package/cors-anywhere – Thinh Vu Aug 11 '21 at 03:02
  • 31-Mar-2022 `https://www.instagram.com/therock/?__a=1` still works on my side without login. But I am not sure about rate limiting thing – kusiaga Mar 31 '22 at 13:59
  • Does not work for me (without login) – Mahmood Dehghan May 22 '22 at 07:26
  • 1
    June 2022 this API seems to have been removed – Mikael Finstad Jun 02 '22 at 20:45
  • @MikaelFinstad they deleted it. But as I inspected the Network tab, this link shown up: https://i.instagram.com/api/v1/users/web_profile_info/?username=therock Don't know why it returns with the error response "useragent mismatch". Working on it. – Thinh Vu Jun 05 '22 at 02:52
  • I get timeout error when logging in. how can i fix it? @ThinhVu –  Jul 03 '22 at 12:32
  • @nevo_e re-run the app – Thinh Vu Jul 05 '22 at 03:14
  • @ThinhVu i worked thank your. Also do you have any idea how to get links of saved posts and how to unsave them? –  Jul 06 '22 at 07:32
  • @nevo_e just follow the same step as I did to find the API. (Developer Console -> Network Tab -> Inspect Request) – Thinh Vu Jul 08 '22 at 09:25
39

Enter this url in your browser with the users name you want to find and your access token

https://api.instagram.com/v1/users/search?q=[USERNAME]&access_token=[ACCESS TOKEN]
j0k
  • 22,600
  • 28
  • 79
  • 90
estherz
  • 439
  • 4
  • 2
  • 16
    Sadly; this is flawed :( We've discovered that if you sit refreshing this url, you can randomly get other users whose username start with the username you searched for. Eg. if you're searching for "fred1" but there's also a "fred123", you'll get random results! Reported to instagram; awaiting a response :( – Danny Tuppeny Aug 13 '14 at 09:06
  • @frosty I find it pretty unreliable—you've had better results? – sambecker Jan 13 '16 at 15:53
  • This doesn't work, since you need "public_content" permission for this. – desloovere_j Mar 17 '16 at 08:18
  • @DannyTuppeny Did you ever hear back from Instagram? – Queue Jul 13 '16 at 23:14
  • @Queue Nothing useful, just garbage. Eventually we gave up and since their changes in June which totally broke our integration anyway, we're just ripping them out of our app completely. – Danny Tuppeny Jul 14 '16 at 17:09
28

Working solution without access token (last checked: April 25, 2023):

Search for the username:

https://www.instagram.com/web/search/topsearch/?query=<username>

Example:

https://www.instagram.com/web/search/topsearch/?query=therock

This is a search query. Find the exact matched entry in the reply and get user ID from the entry.

lashgar
  • 5,184
  • 3
  • 37
  • 45
20

Easily Get USER ID and User Details

https://api.instagram.com/v1/users/search?q=[ USER NAME ]&client_id=[ YOU APP Client ID ]

For Example:

https://api.instagram.com/v1/users/search?q=zeeshanakhter2009&client_id=enter_your_id

Result:

{"meta":{"code":200},"data":[{"username":"zeeshanakhter2009","bio":"http://about.me/zeeshanakhter","website":"http://zeeshanakhter.com","profile_picture":"http://images.ak.instagram.com/profiles/profile_202090411_75sq_1377878261.jpg","full_name":"Zeeshan Akhter","id":"202090411"}]}

Siyu
  • 11,187
  • 4
  • 43
  • 55
Zeeshan Akhter
  • 1,881
  • 20
  • 19
  • 1
    Easiest way. And there is no need for an access token! Love it :) – Can Vural Feb 25 '14 at 10:14
  • 1
    i also write the helping topic on that in java u can see in details http://latest-tutorial.com/2014/01/27/get-instagram-media-comments/ – Zeeshan Akhter Feb 25 '14 at 18:24
  • 6
    Sadly; this is flawed :( We've discovered that if you sit refreshing this url, you can randomly get other users whose username start with the username you searched for. Eg. if you're searching for "fred1" but there's also a "fred123", you'll get random results! Reported to instagram; awaiting a response :( – Danny Tuppeny Aug 13 '14 at 09:07
  • 1
    I agree with Danny, this method does not always work. – c-a May 22 '15 at 14:51
  • yes i knew that .... its for random user search and one thing more interesting i have 3lac + users details and i found that when ever user changes its name instagram never update its username against its profileID that's why you will get many usernames against one profileId... – Zeeshan Akhter May 23 '15 at 21:53
  • 1
    So what if it returns multiple results - as a developer doing proper procedures you should be confirming that a given users_id is the correct one - it is for this reason that the api also delivers the full name and profile image. YOU should be developing a check-system, and not just accepting the first one listed. – Abela May 24 '15 at 05:47
  • Yes i agreed, its all depend on user of API how to use it, here i have concern why instagram giving multiple usernames against one profileID. – Zeeshan Akhter May 25 '15 at 04:18
  • @Zeeshan Does this still work? I just tried it with curl using the format described above and get: `{"meta":{"error_type":"OAuthAccessTokenException","code":400,"error_message":"The access_token provided is invalid."}}` – JMac Feb 03 '16 at 10:06
  • @JMac yes its working but you have to create your APP Client ID – Zeeshan Akhter Feb 04 '16 at 10:52
  • @ZeeshanAkhter thanks, it seemed my problem was that my App was in sandbox mode; in this mode I can't do anything to anyone else who is not in my sandbox. – JMac Feb 08 '16 at 03:44
  • 2
    No longer works since Instagram have removed all client_id support as of 1st June 2016 – Malcolm Box Jun 08 '16 at 17:36
  • below worked for me, At the little command prompt enter: window._sharedData.entry_data.ProfilePage[0].user.id and hit enter – f-society Jul 05 '16 at 17:47
18

Most of the methods are obsolete since June, 1/2016 api changes

Below worked for me,

  • access instagram on your browser say chrome, safari or firefox.
  • Launch developer tools, go to console option.
  • on command prompt enter below command and hit enter:

    window._sharedData.entry_data.ProfilePage[0].user.id
    

If you are lucky, you will get at first attempt, if not, be patient, refresh the page and try again. keep doing until you see user-id. Good luck!!

f-society
  • 2,898
  • 27
  • 18
  • 1
    Here's an example code for this solution. https://github.com/vhpoet/liltools/blob/master/index.js#L13-L28 Hosted: http://liltools.com/instagram – Vahe Hovhannisyan Aug 08 '16 at 21:58
14

Instead of using the API, one can examine the Instagram userpage to get the id. Example code in PHP:

$html = file_get_contents("http://instagram.com/<username>");
$doc = new DOMDocument();
$doc->loadHTML($html);

$xpath = new DOMXPath($doc);
$js = $xpath->query('//body/script[@type="text/javascript"]')->item(1)->nodeValue;

$start = strpos($js, '{');
$end = strrpos($js, ';');
$json = substr($js, $start, $end - $start);

$data = json_decode($json, true);
$data = $data["entry_data"]["UserProfile"][0];
# The "userMedia" entry of $data now has the same structure as the "data" field
# in Instagram API responses to user endpoints queries

echo $data["user"]["id"];

Of course, this code has to be adapted if Instagram changes its page format.

Percival Ulysses
  • 1,133
  • 11
  • 18
  • 4
    Seems like a bad idea to not use the API – 472084 Sep 29 '15 at 22:08
  • 2
    As the answer by Thinh Vu mentions, you can add `?__a=1` to get just the JSON in the `window._sharedData` object, so that you can do something like `curl https://www.instagram.com/username/?__a=1|jq -r .user.id`. – nisetama Aug 09 '16 at 19:30
7

Currently there is no direct Instagram API to get user id from user name. You need to call the GET /users/search API and then iterate the results and check if the username field value is equal to your username or not, then you grab the id.

null
  • 8,669
  • 16
  • 68
  • 98
6

I wrote this tool for retrieving Instagram IDs by username: Instagram User ID Lookup.

It utilizes the python-instagram library to access the API and includes a link to the source code (written on Django), which illustrates various implementations of the Instagram API.

Update: Added source code for port to Ruby on Rails.

zeantsoi
  • 25,857
  • 7
  • 69
  • 61
6

I tried all the aforementioned solutions and none works. I guess Instagram has accelerated their changes. I tried, however, the browser console method and played around a bit and found this command that gave me the user ID.

window._sharedData.entry_data.ProfilePage[0].graphql.user.id

You just visit a profile's page and enter this command in the console. You might need to refresh the page for this to work though. (I had to post this as an answer, because of my low reputation)

ionpan
  • 101
  • 2
  • 9
4

You need to use Instagrams API to convert your username to id.

If I remember correctly you use users/search to find the username and get the id from there

mlishn
  • 1,689
  • 14
  • 19
  • Can you tell me the method that does that !? – Muhammad Reda Aug 03 '12 at 13:19
  • does what? the search is achieved by the API request `users/search`, then you get the `id` and use it in whatever youd like – mlishn Aug 03 '12 at 13:23
  • 4
    Sadly; this is flawed :( We've discovered that if you sit refreshing this url, you can randomly get other users whose username start with the username you searched for. Eg. if you're searching for "fred1" but there's also a "fred123", you'll get random results! Reported to instagram; awaiting a response :( – Danny Tuppeny Aug 13 '14 at 09:07
  • replace username with actual username in below link https://api.instagram.com/v1/users/search?q=username&access_token=141970.467ede5.edbc9c37472d41b790e1db8948793f11 – Chhatrapati Sharma Mar 31 '16 at 17:35
4

Most of these answers are invalid after the 6/1/2016 Instagram API changes. The best solution now is here. Go to your feed on instagram.com, copy the link address for any of your pictures, and paste it into the textbox on that page. Worked like a charm.

Southerneer
  • 1,962
  • 1
  • 13
  • 21
3

to get your id, make an authenticated request to the Instagram API users/self/feed endpoint. the response will contain, among other data, the username as well as the id of the user.

wehal3001
  • 761
  • 5
  • 12
2

Although it's not listed on the API doc page anymore, I found a thread that mentions that you can use self in place of user-id for the users/{user-id} endpoint and it'll return the currently authenticated user's info.

So, users/self is the same as an explicit call to users/{some-user-id} and contains the user's id as part of the payload. Once you're authenticated, just make a call to users/self and the result will include the currently authenticated user's id, like so:

{
    "data": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
        "bio": "This is my bio",
        "website": "http://snoopdogg.com",
        "counts": {
            "media": 1320,
            "follows": 420,
            "followed_by": 3410
        }
}
markquezada
  • 8,444
  • 6
  • 45
  • 52
2

Go to the api console & copy link https://api.instagram.com/v1/users/self in text field and authenticate using your instagram id & password, you will get your id in response

lmcanavals
  • 2,339
  • 1
  • 24
  • 35
sharmaravi
  • 137
  • 3
  • 13
2

You can do this by using Instagram API ( User Endpoints: /users/search )

how-to in php :

function Request($url) {

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($ch, CURLOPT_HEADER, 0);  

    $result = curl_exec($ch);

    curl_close($ch);

    return $result;

}

function GetUserID($username, $access_token) {

    $url = "https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $access_token;

    if($result = json_decode(Request($url), true)) {

        return $result['data'][0]['id'];

    }

}

// example:
echo GetUserID('rathienth', $access_token);
Universal Electricity
  • 775
  • 1
  • 12
  • 26
  • 3
    Sadly; using users/search this is flawed :( We've discovered that if you sit refreshing this url, you can randomly get other users whose username start with the username you searched for. Eg. if you're searching for "fred1" but there's also a "fred123", you'll get random results! Reported to instagram; awaiting a response :( – Danny Tuppeny Aug 13 '14 at 09:08
2

This can be done through apigee.com Instagram API access here on Instagram's developer site. After loging in, click on the "/users/search" API call. From there you can search any username and retrieve its id.

{
"data": [{
    "username": "jack",
    "first_name": "Jack",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_66_75sq.jpg",
    "id": "66",
    "last_name": "Dorsey"
},
{
    "username": "sammyjack",
    "first_name": "Sammy",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg",
    "id": "29648",
    "last_name": "Jack"
},
{
    "username": "jacktiddy",
    "first_name": "Jack",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg",
    "id": "13096",
    "last_name": "Tiddy"
}]}


If you already have an access code, it can also be done like this: https://api.instagram.com/v1/users/search?q=USERNAME&access_token=ACCESS_TOKEN

preynolds
  • 780
  • 8
  • 13
  • 3
    Sadly; using users/search this is flawed :( We've discovered that if you sit refreshing this url, you can randomly get other users whose username start with the username you searched for. Eg. if you're searching for "fred1" but there's also a "fred123", you'll get random results! Reported to instagram; awaiting a response :( – Danny Tuppeny Aug 13 '14 at 09:08
  • 2
    It's not a flaw -- in fact it's a functionality. It's a *search* api, meaning it functions like the search box in the instagram app. The proper way to retrieve a user id for a user name is to query this search endpoint, *and then iterate over the returned objects and check for an exact username match.* – John Dorian May 22 '15 at 06:04
  • 1
    Upvoted both but as api developers can we please agree to create a user lookup endpoint to avoid this, offering only a search is really annoying – sricks Apr 07 '16 at 21:10
2

Well you can just call this link

http://jelled.com/ajax/instagram?do=username&username=[USER_NAME_GOES_HERE]&format=json

A Khudairy
  • 1,422
  • 1
  • 15
  • 26
2

If you are using implicit Authentication must have the problem of not being able to find the user_id

I found a way for example:

Access Token = 1506417331.18b98f6.8a00c0d293624ded801d5c723a25d3ec the User id is 1506417331

would you do a split single seperated by . obtenies to acces token and the first element

Isaac G Sivaa
  • 1,289
  • 4
  • 15
  • 32
2

I think the best, simplest and securest method is to open your instagram profile in a browser, view source code and look for user variable (ctrl+f "user":{") inside main javascript code. The id number inside user variable should be your id.

This is the code how it looked in the moment of writing this answer (it can, and probably will be changed in future):

"user":{"username":"...","profile_picture":"...","id":"..........","full_name":"..."}},
Bajlo
  • 1,407
  • 2
  • 11
  • 18
2

Here is how you can retrieve your user id from a username:

$url = "https://api.instagram.com/v1/users/search?q=[username]&access_token=[your_token]";
$obj = json_decode(@file_get_contents($url));
echo $obj->data[0]->id;
Nezar Fadle
  • 1,335
  • 13
  • 11
2

Here is a really easy website that works well for me:

http://www.instaid.co.uk/

Or you can do the following replacing 'username' with your Instagram username

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

Or you can login to your Instagram account and use google dev tools and look at the cookies that have been stored. 'ds_user_id' is your user ID

enter image description here

BenEgan1991
  • 637
  • 1
  • 9
  • 15
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/16498363) – Bugs Jun 22 '17 at 12:02
  • @Bugs I have added a more detailed answer. I am just trying to contribute to the stackoverflow community. – BenEgan1991 Jun 27 '17 at 05:50
  • use `window._sharedData.entry_data.ProfilePage[0].graphql.user.id` for new instagram api – rezam Apr 08 '21 at 11:01
2

Working Solution December 14, 2020

For simple usage like 3rd party tools that require an Instagram user ID (like embedding an image feed) I tend to use:

https://www.thekeygram.com/find-instagram-user-id/

because it makes it really easy to copy and paste the Instagram user ID that I am looking for. Unlike most tools I get the results fast, it's free and there are no ads. I recommend you watch the youtube video before using it so you can see how simple it is and get an idea of how it's used:

https://www.youtube.com/watch?v=9HvOroY-YBw

For more advanced usage I recommend:

https://www.instagram.com/{username}/?__a=1

(replace username with the requested username)

For example to find the user ID of the username "instagram" you would use:

https://www.instagram.com/instagram/?__a=1

This is the most advanced way which returns a JSON response and it's great if you are building an app that requires the raw data. You can save it in a database or build some type of front end UI to display it. Example: for a dashboard or on a website. Also, using the url is great because you can get additional attributes about users such as their total follower count and profile bio.

Cpu Nerd
  • 312
  • 2
  • 11
2

Since adding ?__a=1 to a profile URL is not working anymore to get a user ID from a username, we can do it with cURL and jq (the new API endpoint can be found in the network requests of Instagram web version, for example with Firefox Developer Tools):

curl -s 'https://i.instagram.com/api/v1/users/web_profile_info/?username=alanarblanchard' -H 'X-IG-App-ID: 936619743392459' | jq -r .data.user.id

If you are using Instagram in a web browser, you don't need to use the command above and can check the response of the HTTP request directly.

Logging in to Instagram should not be needed but recently I noticed that I need to be logged in and send cookies (maybe because I am using a VPN but in the past it was not needed even with a VPN).

You may also be interested in finding the username from a user ID, in case someone changes frequently the username. I added an answer here: Instagram get username from userId

baptx
  • 3,428
  • 6
  • 33
  • 42
1
https://api.instagram.com/v1/users/search?q="[USERNAME]"&access_token=[ACCESS TOKEN]

Please notice the quotation marks.

This does not always return a valid result but more often than non-quoted one:

https://api.instagram.com/v1/users/search?q="self"&count=1&access_token=[ACCESS TOKEN] 

returns user "self" (id: 311176867)

https://api.instagram.com/v1/users/search?q=self&count=1&access_token=[ACCESS TOKEN]

returns user "super_selfie" (id: 1422944651)

Ion Bazan
  • 723
  • 6
  • 16
1

Working solution ~2018

I've found that, providing you have an access token, you can perform the following request in your browser:

https://api.instagram.com/v1/users/self?access_token=[VALUE]

In fact, access token contain the User ID (the first segment of the token):

<user-id>.1677aaa.aaa042540a2345d29d11110545e2499

You can get an access token by using this tool provided by Pixel Union.

Allan of Sydney
  • 1,410
  • 14
  • 23
1

Python solution with Instaloader external library (install it first with pip)

import instaloader

YOUR_USERNAME = "Your username here"
USERNAME_OF_INTEREST = "Username of interest here"

L = instaloader.Instaloader()
L.interactive_login(YOUR_USERNAME)
profile = instaloader.Profile.from_username(L.context, USERNAME_OF_INTEREST)
print(profile.userid)

With this kind of questions about constantly changing private APIs, I recommend to rely on actively developing libraries, not on the services or answers.

lucidyan
  • 3,575
  • 2
  • 22
  • 24
0

First Create an Application on Instagram and get Client Id for your application

http://instagram.com/developer/

Now just copy paste following Url into browser window by replacing your Username and your Client Id https://api.instagram.com/v1/users/search?q=[Your-username]&client_id=[Your-Client-Id]

you will get a Json Result containing General Information about your account along with your Numeric user Id

Akshay Khale
  • 8,151
  • 8
  • 50
  • 58
0

UPDATED 2021

Just go to Facebook Apps choose your app connected with Instagram and you will see your Instagram ID: ********

enter image description here

Note https://www.instagram.com/{username}/?__a=1 was NOT working for me, so this is not a solution in 2021 if you want to use the Instagram Graph API

Dimitar
  • 1,830
  • 5
  • 32
  • 52
  • It's still work but in tricky way. See my updated solution in the top of this thread (The accepted answer). Solution Number 2 should work in every case. – Thinh Vu Mar 19 '22 at 18:20
0

As of june 2022, you can to run or intercept a special HTTP request in order to successfully get the user data (and user ID). If you use Puppeteer, you can intercept the request that Instagram makes in the browser, and read its response. Example code:

const username = 'user.account';

const page = await browser.newPage();

const [foundResponse] = await Promise.all([
  page.waitForResponse((response) => {
    const request = response.request();
    return request.method() === 'GET' && new RegExp(`https:\\/\\/i\\.instagram\\.com\\/api\\/v1\\/users\\/web_profile_info\\/\\?username=${encodeURIComponent(username.toLowerCase())}`).test(request.url());
  }),
  page.goto(`https://instagram.com/${encodeURIComponent(username)}`),
]);

const json = JSON.parse(await foundResponse.text());
console.log(json.data.user);

See discussion here: https://github.com/mifi/SimpleInstaBot/issues/125#issuecomment-1145354294

See also working code here: https://github.com/mifi/instauto/blob/2de64d9a30dad16c89a8c45f792e10f137a8e6cb/src/index.js#L250

Mikael Finstad
  • 684
  • 6
  • 12