Link to Instagram profile with user ID

狂风中的少年 提交于 2019-11-30 02:54:12

问题


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


回答1:


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.




回答2:


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>



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/17683272/link-to-instagram-profile-with-user-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!