如何使用Instagram API获取特定用户的帖子?

时间:2015-10-27 14:32:27

标签: javascript ajax instagram-api

我想收到特定用户的近期帖子,比如Banksy。 我想出了以下内容,但它会给我一个错误:

GET https://api.instagram.com/v1/users/banksy/media/recent/?access_token=225356…1f641437&callback=jQuery11110924438442569226_1445956181244&_=1445956181245

我的ajax电话看起来像这样:

$.ajax({
            type: "GET",
            dataType: "jsonp",
            cache: false,
            url: "https://api.instagram.com/v1/users/banksy/media/recent/?access_token=2253563781.137bf98.bd1c3693d2b84f80a7ab8d661f641437",
            success: function(response) {
                console.log('jfsdahuifhasudh')
                console.log(response);
                // placing the images on the page
                // for (var i = 0; i < 6; i++) {

                    var html = '<a href="' + response.data[i].link + '" >'+
                    '<img src="' + response.data[i].images.low_resolution.url + '" alt="thumbnail" /></a>';
                    $(".instafeed").html(html);

                // }
            }, 

            error: function(data) {
                console.log('We have a problem!');
            }
        });

1 个答案:

答案 0 :(得分:2)

您在查询中使用了用户名;在你的情况下banksyResolve the username into ID然后在您的查询中使用id。例如;

  

https://api.instagram.com/v1/users/45951573/media/recent/?access_token= {令牌}

*如果该帐户是公开的,则API会返回的帖子。

修改

要使用特定主题标签标记帖子,请使用:

  

https://api.instagram.com/v1/tags/ {标签名称} /媒体/最近?的access_token = {}记号

Further reading: Instagram API; Tags

更新

instaJS是我过去写的一个jQuery插件。此插件的独特之处在于它接受username而不是强制用户解析其id。完全免费使用:),当然也欢迎贡献InstaJS on Github