最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Link to Instagram profile with user ID - Stack Overflow

programmeradmin4浏览0评论

I want to link to a profile/user account on Instagram. I have the user ID, but the I can't find the answer in the developer API documentation. I've tried instagram/userID and instagram/users/userID but these aren't working. Simple question: I have just a single <a> tag and I want to know what goes in the href to take the user to a specific instagram profile. Or possibly a window.location in javascript.

Or if there's a way to get the username from the ID, I suppose I could also do it in that round-a-bout way...

I want to link to a profile/user account on Instagram. I have the user ID, but the I can't find the answer in the developer API documentation. I've tried instagram.com/userID and instagram.com/users/userID but these aren't working. Simple question: I have just a single <a> tag and I want to know what goes in the href to take the user to a specific instagram profile. Or possibly a window.location in javascript.

Or if there's a way to get the username from the ID, I suppose I could also do it in that round-a-bout way...

Share Improve this question edited May 7, 2019 at 22:17 Kamil Kiełczewski 92.4k34 gold badges394 silver badges370 bronze badges asked Jul 16, 2013 at 17:30 smilebombsmilebomb 5,4839 gold badges52 silver badges86 bronze badges 4
  • Do you need any more help with your question or did one of the answers already help you solve it. If so, please remember to accept it. Otherwise I'll try to help. – Tim Bodeit Commented Sep 1, 2013 at 22:10
  • @TimBodeit The answers did not help. I ended up using the user name instead of ID. – smilebomb Commented Sep 3, 2013 at 12:54
  • Yes there is a quick way. Answered in here – Hapsher Commented Apr 13, 2018 at 12:34
  • stackoverflow.com/questions/59526137/… – Amrut Bidri Commented Dec 30, 2019 at 6:27
Add a comment  | 

8 Answers 8

Reset to default 3

I am not aware of a solution, that makes it work as a simple link.

You will need to use the Instagram API and sign up your application so that you have a Client-ID.

Next, you will need to do the following request as HTTP GET:

https://api.instagram.com/v1/users/userID?client_id=YourClientID

This will return a JSON-Result, which will contain the username inside the data section.

Now you can use http://instagram.com/username as your link.

1st Method

<a href="http://instagram.com/_u/{USERNAME}/">Link to Instagram Page</a>

  • Ask user to select application to launch with

2nd Method

<a href="instagram://user?username={USERNAME}">Link to Instagram Profile</a>

  • If user installed instagram application : Directly launch page with native application
  • If user not installed instagram application : Do nothing

Tested on Android 4.4 Chrome

try

async function insta(uid) {
  let api = `https://i.instagram.com/api/v1/users/${uid}/info/`
  let info = await (await fetch(api)).json();
  return `https://www.instagram.com/${info.user.username}`;
}

async function go() {
  let url = await insta(userId.value);
  link.innerText = url;
}
Type instagram user id:
<input id="userId" value=182805585 />
<button onclick="go()">Find username</button><br>
<pre id="link"></pre>

UPDATE

According this starting form 03.12.2019 above solution stops works and returns only

{“message”: “useragent mismatch”, “status”: “fail”}

instead you can try to send request GET

https://i.instagram.com/api/v1/users/1791879548/info/

with following user-agent header:

Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 105.0.0.11.118 (iPhone11,8; iOS 12_3_1; en_US; en-US; scale=2.00; 828x1792; 165586599)
https://www.instagram.com/p/" . $social_id . "/"

async function insta(uid) {
  let api = `https://i.instagram.com/api/v1/users/${uid}/info/`
  let info = await (await fetch(api)).json();
  return `https://www.instagram.com/${info.user.username}`;
}

async function go() {
  let url = await insta(userId.value);
  link.innerText = url;
}
Type instagram user id:
<input id="userId" value=182805585 />
<button onclick="go()">Find username</button><br>
<pre id="link"></pre>

async function insta(uid) {
  let api = `https://i.instagram.com/api/v1/users/${uid}/info/`
  let info = await (await fetch(api)).json();
  return `https://www.instagram.com/${info.user.username}`;
}

async function go() {
  let url = await insta(userId.value);
  link.innerText = url;
}
Type instagram user id:
<input id="userId" value=182805585 />
<button onclick="go()">Find username</button><br>
<pre id="link"></pre>


arifa_a235668

async function insta(uid) {
  let api = `https://https://instagram.com/priyasharma_officle?igshid=MzRlODBiNWFlZA==

> *

Blockquote

*

/api/v1/users/${uid}/info/`
  let info = await (await fetch(api)).json();
  return `https://www.instagram.com/${info.user.username}`;
}

async function go() {
  let url = await insta(userId.value);
  link.innerText = url;
}
Type instagram user id:
<input id="userId" value=https://instagram.com/priyasharma_officle?igshid=MzRlODBiNWFlZA==/>
<button onclick="go()">Find username</priyasharma_officle><br>
<pre id="link"></pre>

You can also use this: https://instagram.com/user/?id={USER_ID}

发布评论

评论列表(0)

  1. 暂无评论