Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 429
ssthormess Avatar asked Oct 04 '17 20:10

ssthormess


2 Answers

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.

like image 144
aandergr Avatar answered Nov 07 '22 20:11

aandergr


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
like image 41
Foad Avatar answered Nov 07 '22 19:11

Foad