Instagram API:从另一个站点获取用户提要

Instagram API: getting users feed from another site

我正在尝试获取某个用户发布的最后几张照片。

在这个网站上,我找到了很多答案,说没有身份验证令牌(例如,How can I get a user's media from Instagram without authenticating as a user?)也可以做到这一点。

每当我在浏览器上打开 https://api.instagram.com/v1/users/search?q=cocacola&client_id=5c314c67157f4585ba3041281540c59b 时,我都会收到有效的 json 响应。但是当我在我的网站上对 javascript 执行获取请求时,它失败了。

编辑:为了将来参考,问题与跨域请求有关。

您需要使用jsonp,例如:

$.ajax({
    url: "https://api.instagram.com/v1/users/search?q=cocacola&client_id=5c314c67157f4585ba3041281540c59b", 
    // Tell jQuery we're expecting JSONP
    dataType: "jsonp",
    success: function( response ) {
        console.log( response ); // server response
    }
});

-DEMO-