7

I have the ability to get userId from username, but I do not have the ability to get username from userId.

I have a database of userId because that is all my app needed to function, but I want to know who these users are or look at their profiles. I have to otherwise update my app to write the username to the database in a new column, taking up space that the app itself doesn't really need

CQM
  • 42,592
  • 75
  • 224
  • 366

4 Answers4

5

Here is a way to find an Instagram username by user ID without using an access token (logging in to Instagram should not be needed but I am using a VPN and noticed that it asks me to log in).

You first have to change your user agent to something like Instagram 85.0.0.21.100 Android (23/6.0.1; 538dpi; 1440x2560; LGE; LG-E425f; vee3e; en_US) (update: this step does not seem necessary anymore) . If you want to find a username on a web browser instead of a command line tool like cURL, you can use an open source browser addon like Header Editor on Firefox (https://addons.mozilla.org/en-US/firefox/addon/header-editor/) to send this user agent only on the domain name i.instagram.com. Then you can access an URL like https://i.instagram.com/api/v1/users/5995367/info/ (replace the user ID with the one you want). If this does not work, you can try copying a working request as cURL, for example from your web browser network monitor and replace the URL.

This URL returning JSON is from Instagram private API, which is used by the Instagram mobile app and third-party apps like IG:dm. If you log in to Instagram web version, this URL will return more data. Searching a username by user ID can be useful to find a user changing frequently usernames, in case you did not already send them a message or follow them.

Note: to find the user ID, it was possible to add ?__a=1 to a profile URL, for example https://www.instagram.com/alanarblanchard/?__a=1 (this URL returning JSON also was used when you clicked on a user profile with Instagram web version but it is not working anymore so I added another answer with a new solution: Instagram how to get my user id from username?).

baptx
  • 3,428
  • 6
  • 33
  • 42
4

Instagram exposes a User Endpoint for that. From http://instagram.com/developer/endpoints/users/#get_users, you can use:

https://api.instagram.com/v1/users/(user id)/?access_token=ACCESS-TOKEN

The response is JSON and the data you want is data.username

Tyress
  • 3,573
  • 2
  • 22
  • 45
  • 1
    Okay, happy? :) At first when I awarded the answer SO had showed me the exact same time stamp for both answers – CQM Nov 10 '14 at 23:37
3

use this API:

https://api.instagram.com/v1/users/<USER-ID>/?access_token=ACCESS-TOKEN

The response will have username and other user information, here is documentation: http://instagram.com/developer/endpoints/users/#get_users

krisrak
  • 12,882
  • 3
  • 32
  • 46
0

With the new update, Instagram gives the username who message or contact you. But you can get the username with the token. You can get these fields ;

  • name,
  • username,
  • profile_pic,
  • follower_count,
  • is_user_follow_business,
  • is_business_follow_user

Get request is ;

https://graph.facebook.com/v14.0/{user_id}?fields=name,username,profile_pic,follower_count,is_user_follow_business,is_business_follow_user&access_token={ACCESS_TOKEN}

Real data example ;

https://graph.facebook.com/v14.0/4852337454545454?fields=name,username,profile_pic,follower_count,is_user_follow_business,is_business_follow_user&access_token=EAALKZAsNrmg0aVZSlOwkwJ7UyZBEy6ihcVgeQ8n3X2hTdZB7M9j2PHq388gPWQAhxMHAF8hIYH0Verw0uwB3Ajvg3JEYaQ5b5i9O3KzEAbppHktwwsBADIHOCKj5VAGJ5Qu3QnBcHEfOAPQnGfmZAfi5kosNNqakLqo3LM5eHpxJ7Jh1CCjlgH
Abdullah alkış
  • 325
  • 4
  • 13