How to retrieve Instagram username from User ID?

16,581

Solution 1

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.

Solution 2

You can use this API (from official instagram site) to fetch username by user static id:

GET https://www.instagram.com/graphql/query/?query_hash=c9100bf9110dd6361671f113dd02e7d6&variables={"user_id": ${user_id}}

Replace ${user_id} with actual user id.

const username = result.data.user.reel.owner.username

Solution 3

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

Solution 4

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"
}
Share:
16,581
ssthormess
Author by

ssthormess

Lazy IT Consultant, Friend of a Few, what else?

Updated on June 28, 2022

Comments

  • ssthormess
    ssthormess about 2 years

    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.