ssthormess
ssthormess

Reputation: 71

How to retrieve Instagram username from User ID?

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.

Upvotes: 7

Views: 45773

Answers (6)

user23207388
user23207388

Reputation: 1

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",
    ...
  }
}

Upvotes: 0

Michael Kris
Michael Kris

Reputation: 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.

Upvotes: -1

Fusillo
Fusillo

Reputation: 31

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

Upvotes: 1

Birbal Zimba
Birbal Zimba

Reputation: 23

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"
}

Upvotes: 2

aandergr
aandergr

Reputation: 637

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.

Upvotes: 13

João Armando
João Armando

Reputation: 167

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

Upvotes: 2

Related Questions