Given a user_id, how do I find the username?
You can access it without needing API via internal /user/
endpoint instagram uses for AJAX requests:
https://i.instagram.com/api/v1/users/{user_id}/info/
where {user_id}
is numeric user id like 6817966272
.
Returned response example (see user['username']
key for username):
GET https://i.instagram.com/api/v1/users/6817966272/info/
{
"user": {
"pk": 6817966272,
"username": "myriaamaa",
"full_name": "\u2661",
"is_private": false,
"profile_pic_url": "https://instagram.fcnx2-1.fna.fbcdn.net/vp/66486d198fc02046d04d7bc11e51e54a/5D913015/t51.2885-19/s150x150/61226760_298998544311382_2345929352031502336_n.jpg?_nc_ht=instagram.fcnx2-1.fna.fbcdn.net",
"profile_pic_id": "2056076981860037983_6817966272",
"is_verified": false,
"has_anonymous_profile_picture": false,
"media_count": 216,
"follower_count": 4926,
"following_count": 83,
"following_tag_count": 0,
"biography": "YOU. ARE. HOLY \ud83c\udf19",
"external_url": "",
"total_igtv_videos": 0,
"total_ar_effects": 0,
"usertags_count": 6,
"is_favorite": false,
"is_interest_account": true,
"hd_profile_pic_versions": [
{
"width": 320,
"height": 320,
"url": "https://instagram.fcnx2-1.fna.fbcdn.net/vp/fafecdc76c82de85580c9c03d14b1aaa/5D9BD2E5/t51.2885-19/s320x320/61226760_298998544311382_2345929352031502336_n.jpg?_nc_ht=instagram.fcnx2-1.fna.fbcdn.net"
},
{
"width": 640,
"height": 640,
"url": "https://instagram.fcnx2-1.fna.fbcdn.net/vp/0ec5339e3958c9c41414e5378fa2443c/5D7DD28A/t51.2885-19/s640x640/61226760_298998544311382_2345929352031502336_n.jpg?_nc_ht=instagram.fcnx2-1.fna.fbcdn.net"
}
],
"hd_profile_pic_url_info": {
"url": "https://instagram.fcnx2-1.fna.fbcdn.net/vp/8b3859950f0bb8e1a4a8f65566992b78/5D9132EF/t51.2885-19/61226760_298998544311382_2345929352031502336_n.jpg?_nc_ht=instagram.fcnx2-1.fna.fbcdn.net",
"width": 774,
"height": 774
},
"mutual_followers_count": 0,
"has_highlight_reels": true,
"can_be_reported_as_fraud": false,
"is_business": false,
"account_type": 1,
"is_call_to_action_enabled": null,
"include_direct_blacklist_status": true,
"is_potential_business": true,
"is_bestie": false,
"has_unseen_besties_media": false,
"show_account_transparency_details": false,
"auto_expand_chaining": false,
"highlight_reshare_disabled": false
},
"status": "ok"
}
EDIT 2019-10:
This endpoint only serves user-agents that identify themselves as instagram app.
I got it working with iphone's instagram user agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 Instagram 12.0.0.16.90 (iPhone9,4; iOS 10_3_3; en_US; en-US; scale=2.61; gamut=wide; 1080x1920)
For more check out this online user agent database: https://developers.whatismybrowser.com/useragents/explore/software_name/instagram/1
# top 5:
Mozilla/5.0 (Linux; Android 8.1.0; motorola one Build/OPKS28.63-18-3; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.80 Mobile Safari/537.36 Instagram 72.0.0.21.98 Android (27/8.1.0; 320dpi; 720x1362; motorola; motorola one; deen_sprout; qcom; pt_BR; 132081645)
Mozilla/5.0 (Linux; Android 7.0; Lenovo K33b36 Build/NRD90N; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/65.0.3325.109 Mobile Safari/537.36 Instagram 41.0.0.13.92 Android (24/7.0; 480dpi; 1080x1920; LENOVO/Lenovo; Lenovo K33b36; K33b36; qcom; pt_BR; 103516666)
Mozilla/5.0 (Linux; Android 5.0.1; LG-H342 Build/LRX21Y; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/65.0.3325.109 Mobile Safari/537.36 Instagram 40.0.0.14.95 Android (21/5.0.1; 240dpi; 480x786; LGE/lge; LG-H342; c50ds; c50ds; pt_BR; 102221277)
Mozilla/5.0 (Linux; Android 6.0.1; SM-G610M Build/MMB29K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/65.0.3325.109 Mobile Safari/537.36 Instagram 41.0.0.13.92 Android (23/6.0.1; 480dpi; 1080x1920; samsung; SM-G610M; on7xelte; samsungexynos7870; pt_BR; 103516666)
Mozilla/5.0 (Linux; Android 8.0.0; SM-A520F Build/R16NW; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36 Instagram 46.0.0.15.96 Android (26/8.0.0; 480dpi; 1080x1920; samsung; SM-A520F; a5y17lte; samsungexynos7880; pt_BR; 109556226)
Edit 2020-05/2022-05: Currently this endpoint returns less information but username is still present:
{
"user": {
"username": "meram.ba",
"pk": 6817966272,
"profile_pic_url": "https://instagram.fbkk5-5.fna.fbcdn.net/v/t51.2885-19/s150x150/93795245_228684278392964_3931284463400517632_n.jpg?_nc_ht=instagram.fbkk5-5.fna.fbcdn.net&_nc_ohc=O6-_BTmMHUIAX9Qy8up&oh=8303e6fc8444b920c0c0edc603c917b5&oe=5EE91CF3"
},
"status": "ok"
}
If you don't have approved instagram application I suggest to use this php library: https://github.com/postaddictme/instagram-php-scraper
$instagram = Instagram::withCredentials('username', 'password', 'path/to/cache/');
$account = $instagram->getAccountById('193886659');
echo $account->getUsername();
Or direct access:
https://www.instagram.com/query/?q=ig_user(3){id,username,external_url,full_name,profile_pic_url,biography,followed_by{count},follows{count},media{count},is_private,is_verified}
Update: This url doesn't work anymore. You need to use POST. See repo to know how