【问题标题】:Display Instagram photos from different account to my webpage在我的网页上显示来自不同帐户的 Instagram 照片
【发布时间】:2014-07-03 14:26:39
【问题描述】:

我正在寻找不将我的 instagram 照片显示到我的网站页面的方法,但不能。 如果我只有一个 instagram 用户的帐户名(例如 jamieoliver),是否可以这样做。 我的网站是在 Wordpress 上编写的。

需要显示不是我的图片

【问题讨论】:

    标签: jquery ajax wordpress instagram


    【解决方案1】:

    此 URL 格式 http://instagram.com/{instagram user name}/media 将返回一个 json 文件,其中包含来自该用户的最新 (20+/-) 媒体文件。

    jamieoliver的例子中你可以做http://instagram.com/jamieoliver/media

    您可以通过 (jQuery) ajax 调用来处理 json 响应,例如:

    $.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 格式的外观。如果您使用的是 WordPress,也许您可​​以找到一个插件来处理该 json 响应


    编辑

    http://instagram.com/{author_name}/media 的响应似乎不是 jsonp 而是 json(请参阅 this 以获取更多参考),但是设置 json dataType 将返回跨域错误。

    解决方法是使用whateverorigin.org第三方应用来规避同源策略。

    所以像

    这样格式化你的 URL
    "http://whateverorigin.org/get?url=" + encodeURIComponent("http://instagram.com/{author_name}/media");
    

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

    注意,您仍然需要在 ajax 调用中使用 dataType : "jsonp"

    JSFIDDLE

    【讨论】:

    • 我在尝试获取该数据时遇到错误 Uncaught SyntaxError: Unexpected token :
    • 这是返回给我的网址instagram.com/hestonology/… 有数据,但我总是出错
    • 非常感谢,这真的节省了我的时间
    • 嘿@JSK,有没有办法从该帐户加载更多图像,我想通过单击某个按钮或向下滚动来加载更多数据,例如这里hoopshype.com/social/gallery.html#,是否可以这样做?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 2014-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多