Html 使用用户 ID 链接到 Instagram 个人资料

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17683272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:13:34  来源:igfitidea点击:

Link to Instagram profile with user ID

javascripthtmlhrefinstagram

提问by smilebomb

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/userIDand instagram.com/users/userIDbut these aren't working. Simple question: I have just a single <a>tag and I want to know what goes in the hrefto take the user to a specific instagram profile. Or possibly a window.locationin javascript.

我想链接到 Instagram 上的个人资料/用户帐户。我有用户 ID,但我在开发人员 API 文档中找不到答案。我试过了instagram.com/userIDinstagram.com/users/userID但这些都不起作用。简单的问题:我只有一个<a>标签,我想知道href将用户带到特定 Instagram 个人资料的内容。或者可能是window.location在 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...

或者,如果有一种方法可以从 ID 中获取用户名,我想我也可以以这种循环方式进行...

回答by Tim Bodeit

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.

您将需要使用 Instagram API 并注册您的应用程序,以便您拥有一个客户端 ID。

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

接下来,您需要以 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 datasection.

这将返回一个 JSON-Result,其中将包含该data部分中的用户名。

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

现在您可以将其http://instagram.com/username用作链接。

回答by Kamil Kie?czewski

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>

回答by Chemical Programmer

1st Method

第一种方法

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

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

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

  • If user installedinstagram application : Directly launch page with native application
  • If user not installedinstagram application : Do nothing
  • 如果用户安装了Instagram 应用程序:使用本机应用程序直接启动页面
  • 如果用户未安装Instagram 应用程序:什么都不做


Tested on Android 4.4 Chrome

在 Android 4.4 Chrome 上测试

回答by Lorenz W?hr

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

你也可以使用这个:https: //instagram.com/user/ ?id ={USER_ID}