7

How can one retrieve an Instagram username from it's ID using Instagram's API or website? I have gotten a database table which contains Instagram User IDs and I need to know their usernames.

3
  • Welcome to SO. This site is not a code-writing service and is not meant for delivering complete solutions. Users are expected to show some effort and code whilst SO is here to help you solve specific programming problems along the way. Have you tried anything already? Please read: stackoverflow.com/help/asking Commented Oct 4, 2017 at 20:51
  • @MaciejJureczko yes I have tried several options without success. I'm not asking for the code... I'm asking if someone has already achieved this and can enlighten me with their knowledge so I can achieve it myself. Commented Oct 7, 2017 at 1:47
  • 1
    This question is similar to: Given a user_id, how do I find the username?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Feb 16 at 11:45

6 Answers 6

14

One can use https://i.instagram.com/api/v1/users/USERID/info (replace USERID by the user id). It returns a JSON in which the field user.username is that user's username.

With curl and jq installed, this shell oneliner will directly return the username:

curl -s https://i.instagram.com/api/v1/users/USERID/info/ | jq -r .user.username

However, keep in mind that this isn't an official API endpoint.

Sign up to request clarification or add additional context in comments.

3 Comments

@aandergr This command not work anymore, any other suggestions?
curl -A "Instagram 85.0.0.21.100 Android (23/6.0.1; 538dpi; 1440x2560; LGE; LG-E425f; vee3e; en_US)" https://i.instagram.com/api/v1/users/<PROFILE_ID>/info/
Does it return {"message":"useragent mismatch","status":"fail"} for you, too?
3

Need modify the user agent (instagram app's agent), and use some browser web, otherwise use wget.

wget --user-agent="Instagram 85.0.0.21.100 Android (23/6.0.1; 538dpi; 1440x2560; LGE; LG-E425f; vee3e; en_US" https://i.instagram.com/api/v1/users/*SOME_ID_INSTAGRAM*/info/

find your desidered username in file "index.html" saved

Note: to find the user ID, you can add ?__a=1 to a profile URL, for example: https://www.instagram.com/*SOME_USERNAME*/?__a=1

1 Comment

with curl without saving: curl -A "Instagram 85.0.0.21.100 Android (23/6.0.1; 538dpi; 1440x2560; LGE; LG-E425f; vee3e; en_US)" https://i.instagram.com/api/v1/users/*ig-user-id*/info/
2

before continuing I would like to inform you that due to recent experiences, this "solution" is no longer available due to the latest updates in instagram api, but I hope it will contribute to something for you!

You could access the user data that you have the userId through the instagram api through the endpoint: https://api.instagram.com/v1/users/{user-id}/?access_token=ACCESS-TOKEN However this requires [public_content], a permission that needs to be accepted by instagram so you can explore all the "public users" of instagram, this permission is no longer being waited for by instagram.

You can learn more about the instagram endpoints here: https://www.instagram.com/developer/endpoints/users/#get_users

Comments

2

Instagram Graph API In 2019-08-13 Instagram had introduced Business Discovery API where it allows you to get data about other Instagram Business or Creator IG Users.

For that you need following permissions:

  1. instagram_basic
  2. instagram_manage_insights
  3. pages_read_engagement or pages_show_list

First of all you need to fetch your Instagram Business Id using this query

 https://graph.facebook.com/v7.0/{your_instagram_id}?fields=instagram_business_account&access_token={your_access_token}

then you will get Instagram Business Id

{
  "instagram_business_account": {
    "id": "17841430463493290"
  },
  "id": "101345731473817"
}

Using Instagram Business Id and your access token you can fetch anyone's user id from username

Example:

https://graph.facebook.com/v7.0/17841430463493290?fields=business_discovery.username(zimba_birbal){id,username,followers_count,media_count}&access_token={your_access_token}

Response:

    {
   "business_discovery": {
      "id": "17841401828704017",
      "username": "zimba_birbal",
      "followers_count": 166,
      "media_count": 36
   },
   "id": "17841430463493290"
}

Comments

2

Use the following curl command to get the Instagram username from a User ID:

curl -A "Instagram 85.0.0.21.100 Android (23/6.0.1; 538dpi; 1440x2560; LGE; LG-E425f; vee3e; en_US)" https://i.instagram.com/api/v1/users/*ig-user-id*/info/

Replace {user-id} with the actual Instagram User ID. The response will be in JSON format, where you can find the username. Example:

{
  "user": {
    "username": "example_username",
    ...
  }
}

1 Comment

Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?
-1

Data 365 Instagram API that I am currently working for seems to be a suitable tool that may help you.

Birbal Zimba has already described a number of restrictions on the official API in his answer. Instagram API from data365.co doesn't have such limits.

To get the username, you should send requests including the profile_id (the same as the user_id), namely:

POST request to download profile data:

https://api.data365.co/v1.1/instagram/profile/{profile_id}/update?access_token=YOUR ACCESS TOKEN

GET request to receive profile data:

https://api.data365.co/v1.1/instagram/profile/{profile_id}?access_token=YOUR ACCESS TOKEN

You will receive a response not only a username but also a full name, biography, profile photo, business category, user gender and age, number of followers, followings, posts, and much more.

You can see a response example in JSON here.

1 Comment

They charge 100s of USD per month to use their API.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.