php 如何嵌入 Instagram 个人资料?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36500379/
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
How to embed instagram profile?
提问by Xeen
I have found literally hundreds of ways to embed instagram gallery in a website, but what I need is to embed the whole profile, t.i. if you look at this profile for example: https://www.instagram.com/exampleprofile/there's a profile image, about, title and a follow button.
我已经找到了数百种在网站中嵌入 Instagram 画廊的方法,但我需要的是嵌入整个个人资料,例如,如果您查看此个人资料:https: //www.instagram.com/exampleprofile/有一个个人资料图片、关于、标题和一个关注按钮。
How can I embed the profile with this header information as well not only the images in its gallery? Is it even possible?
如何将配置文件与此标题信息以及其图库中的图像一起嵌入?甚至有可能吗?
回答by Tomahock
The right way to do this is to use the API. You can get user information with this endpoint:
正确的方法是使用 API。您可以使用此端点获取用户信息:
https://www.instagram.com/developer/endpoints/users/#get_users
https://www.instagram.com/developer/endpoints/users/#get_users
回答by Omar Alahmed
Actually, there is no straightforward way to do that, you need to:
实际上,没有直接的方法可以做到这一点,您需要:
Create an Instagram Client application
Get your client details
Authenticate
创建 Instagram 客户端应用程序
获取您的客户详细信息
认证
1. Create an Instagram Client application
1. 创建 Instagram 客户端应用程序
You have to create your own instagram application here:
您必须在此处创建自己的 Instagram 应用程序:
2. Get your client details
2. 获取您的客户详细信息
In your Instagram Developer account, click "Manage Clients" and take note of the "Client ID", "Client Secret" and "Redirect URI" because you'll need them soon. Make sure you are using a complete URL for your Redirect URI, such as "https://drupal.org".
在您的 Instagram 开发者帐户中,单击“管理客户”并记下“客户 ID”、“客户密码”和“重定向 URI”,因为您很快就会需要它们。确保为重定向 URI 使用完整的 URL,例如“ https://drupal.org”。
3. Authenticate
3. 认证
3.a Using CURL First, add this into your browser:
3.a 使用 CURL 首先,将其添加到您的浏览器中:
https://api.instagram.com/oauth/authorize/?client_id=YOUR-CLIENT-ID&redirect_uri=YOURREDIRECT-URI&response_type=code&scope=public_content Note that the REDIRECT-URI above should be URL encoded, such as https%3A%2F%2Fdrupal.org.
https://api.instagram.com/oauth/authorize/?client_id=YOUR-CLIENT-ID&redirect_uri=YOURREDIRECT-URI&response_type=code&scope=public_content 注意上面的REDIRECT-URI应该是URL编码的,比如https%3A%2F %2Fdrupal.org。
You'll then be redirected to the url you redirected to. Take note of the url as this is where you receive the code you need:
然后,您将被重定向到您重定向到的 url。记下网址,因为这是您收到所需代码的地方:
http://your-redirect-uri?code=YOU-NEED-THIS-CODE
Now open up your terminal and paste in this (adding your specific id, secret, redirect uri, & code):
现在打开您的终端并粘贴(添加您的特定 ID、秘密、重定向 uri 和代码):
curl -F 'client_id=YOUR CLIENT_ID HERE' \
-F 'client_secret=YOUR CLIENT_SECRET HERE' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=YOUR AUTHORIZATION_REDIRECT_URI HERE' \
-F 'code=THE CODE YOU RECEIVED' \
https://api.instagram.com/oauth/access_token
You should receive something that looks like this:
您应该会收到如下所示的内容:
{
"access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
"user": {
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "..."
}
}
3.b Using browserBuild the following url and paste it on your browser:
3.b 使用浏览器构建以下网址并将其粘贴到您的浏览器中:
https://api.instagram.com/oauth/authorize/?client_id=[your client id]&redirect_uri=[your redirect uri]&response_type=token
You may see the following error "Implicit authentication is disabled". If so, then you have to edit your Instagram Client, go to the Security tab, and disable the option Disable implicit OAuth, you can enable this back once you get to the following point.
您可能会看到以下错误“隐式身份验证已禁用”。如果是这样,那么您必须编辑您的 Instagram 客户端,转到安全选项卡,并禁用禁用隐式 OAuth选项,您可以在到达以下点后重新启用它。
If everything went well you should have been redirected to an URI that looks like this
如果一切顺利,你应该被重定向到一个看起来像这样的 URI
https://my_redirect.uri/#access_token=xxxxxxxxxx.yyyyyyy.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
On the access_token key, the "x" part (all before the first period) is your User Id.
在 access_token 键上,“x”部分(全部在第一个句点之前)是您的用户 ID。
4. Create request for Instagram API and then parse the response object
4. 创建 Instagram API 请求,然后解析响应对象
https://api.instagram.com/v1/users/xxxxxxxxxx/media/recent/?access_token=xxxxxxxxxx.yyyyyyy.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Instagram API: https://www.instagram.com/developer/endpoints/users/#get_users
Instagram API:https: //www.instagram.com/developer/endpoints/users/#get_users
The source:https://www.drupal.org/node/2746185
回答by jakeonfire
You can do this using the new Facebook Graph API: https://developers.facebook.com/docs/instagram-basic-display-api/reference/media
您可以使用新的 Facebook Graph API 执行此操作:https: //developers.facebook.com/docs/instagram-basic-display-api/reference/media
You'll need a developer account with an Application and Instagram "Basic Display" permissions. From there, much of Omar Alahmed's answeris still applicable, including authorization via OAuth at https://api.instagram.com(this part of the API was not deprecated).
您需要一个具有应用程序和 Instagram“基本显示”权限的开发者帐户。从那里开始,Omar Alahmed 的大部分答案仍然适用,包括通过https://api.instagram.com上的 OAuth 进行授权(API 的这一部分未被弃用)。