javascript Instagram API 和导入照片而无需服务器端身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7396760/
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
Instagram API and importing photos without server side authentication
提问by jeffreynolte
I am a bit confused on a certain functionality I would like to implement into a website using the Instagram API. I would like to access my own feed based on my user ID from the Instagram API and display them on my site. It is saying that there is a way to do client side OAuth authentication but I am a bit confused on how I would go about this. I am fairly okay with JavaScript and if someone could point me in the right direction I am sure I could figure it out.
我对我想使用Instagram API实现到网站中的某些功能感到有些困惑。我想根据我的用户 ID 从 Instagram API 访问我自己的提要,并将它们显示在我的网站上。据说有一种方法可以进行客户端 OAuth 身份验证,但我对如何进行此操作感到有些困惑。我对 JavaScript 还算满意,如果有人能指出我正确的方向,我相信我能弄明白。
Any best practices would be great.
任何最佳实践都会很棒。
Thank you in advance,
先感谢您,
JN
江南
回答by emeth
You're asking how to use Client-Side (Implicit) Authentication for Instagram.
您问的是如何对 Instagram 使用客户端(隐式)身份验证。
Here are a couple JS libraries made for it:
这里有几个为它制作的 JS 库:
回答by phenomnomnominal
This was bugging me for ages, but I think I came up with to a simple way to just get my own photo's on my website, using ideas from the "jquery-instagram" plugin, but stripping it way down.
这一直困扰着我多年,但我想我想出了一个简单的方法来在我的网站上获取我自己的照片,使用来自“jquery-instagram”插件的想法,但将其剥离。
Come up with a #tag and add it to all the photos you want to show on your site, make sure it's not something that just anyone will use. (Do it this way to prevent needing to authenticate anything).
Register your app here: http://instagr.am/developer/register/(Just use your Instagram login)
Use the following code (with jQuery), where "tag" is the tag you used, "id" is your registered app client id, and "photoCount" is the max number of photos you wish to retrieve.
$.ajax({ type: "GET", dataType: "jsonp", cache: false, url: "https://api.instagram.com/v1/tags/" + tag + "/media/recent?client_id=" + id, success: function(response) { var length = response.data != 'undefined' ? response.data.length : 0; var limit = photoCount != null && photoCount < length ? photoCount : length; if(limit > 0) { for(var i = 0; i < limit; i++) { $('<img>', { src: response.data[i].images.standard_resolution.url }).appendTo($("#photos")); } } } });
想出一个#tag 并将其添加到您要在您的网站上显示的所有照片中,确保它不是任何人都会使用的。(这样做可以防止需要对任何内容进行身份验证)。
在此处注册您的应用程序:http: //instagr.am/developer/register/(只需使用您的 Instagram 登录信息)
使用以下代码(使用 jQuery),其中“tag”是您使用的标签,“id”是您注册的应用程序客户端 ID,“photoCount”是您希望检索的最大照片数。
$.ajax({ type: "GET", dataType: "jsonp", cache: false, url: "https://api.instagram.com/v1/tags/" + tag + "/media/recent?client_id=" + id, success: function(response) { var length = response.data != 'undefined' ? response.data.length : 0; var limit = photoCount != null && photoCount < length ? photoCount : length; if(limit > 0) { for(var i = 0; i < limit; i++) { $('<img>', { src: response.data[i].images.standard_resolution.url }).appendTo($("#photos")); } } } });