显示Instagram的照片从不同的帐户,以我的网页 [英] Display Instagram photos from different account to my webpage

查看:176
本文介绍了显示Instagram的照片从不同的帐户,以我的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找显示不是我的Instagram照片到我的网站页面的方式,但不能。 是否有可能做,如果我有Instagram的用户只需一个账户名称(如jamieoliver)。 我的网站上写的字preSS。

I am looking for the way to display not my instagram photos to my website page, but can't. Is it possible to do if i have just an account name of the instagram user (e.g. jamieoliver). My website is written on Wordpress.

需要显示的不是我图片

推荐答案

这个URL格式 http://instagram.com/ {Instagram的用户名} /媒体返回一个JSON文件的最新版本(20 +/-)媒体从该用户的文件。

This URL format http://instagram.com/{instagram user name}/media will return a json file with the latest (20+/-) media files from that user.

jamieoliver ,你可以做 HTTP的例子:/ /instagram.com/jamieoliver/media

您可以处理该 JSON 通过像(jQuery的)AJAX调用响应:

You could process that json response through an (jQuery) ajax call like :

$.ajax({
    url: "http://instagram.com/jamieoliver/media",
    dataType : "jsonp", // this is important
    cache: false,
    success: function(response){
        // process the json response to get images
        // e.g. the first image should be something like : 
        // response.items.images[0].low_resolution
        // you could call an external function to iterate through the response
    }
});

当然,我想你明白什么是JSON格式的模样。如果您使用的是Word preSS,也许你可以找到一个插件来处理这个JSON响应

Of course, I assume you understand what a json format looks like. If you are using WordPress, maybe you could find a plugin to deal with that json response

修改

这似乎是从 http://instagram.com/ {AUTHOR_NAME}响应/媒体不是JSONP但JSON(见的this 备查),但设置一个JSON 的dataType 将返回一个跨域错误。

It seems like the response from http://instagram.com/{author_name}/media is not jsonp but json (see this for further reference), however setting a json dataType will return a cross-domain error.

解决方法是使用 whateverorigin.org 的第三方应用程序,以绕过同源策略。

The workaround is to use whateverorigin.org third-party app to circumvent the same-origin policy.

所以格式化您的URL如

So format your URL like

"http://whateverorigin.org/get?url=" + encodeURIComponent("http://instagram.com/{author_name}/media");

whateverorigin 服务器将充当代理服务器和返回正确的 JSON 格式。

The whateverorigin server will act as proxy and return the proper json format.

注意,你仍然需要使用数据类型:JSONP在Ajax调用

Note that you still need to use dataType : "jsonp" in your ajax call.

请参阅 的jsfiddle

See JSFIDDLE

这篇关于显示Instagram的照片从不同的帐户,以我的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆