Trying to access Instagram API using jQuery

南笙酒味 提交于 2019-11-30 16:35:36

Have the function call itself in the ajax success callback with the new url as a parameter:

$(document).ready(function() {
    $('#fetch_followers').click(function() {
        var $access_token = '{access-token}';
        pollInstagram('https://api.instagram.com/v1/users/{user-id}/followed-by?access_token={access-token}&count=100');
    });
});

function pollInstagram(next_url, count) {
    $.ajax({
        method: "GET",
        url: next_url,
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "jsonpcallback",
        success: function(data) {
            $.each(data.data, function(i, item) {
                $("#log").val($("#log").val() + item.id + '\n');
            });
            $("#log").val($("#log").val() + data.pagination.next_url + '\n');

            // If the next url is not null or blank:
            if( data.pagination.next_url && count <=50 ) {
                pollInstagram(data.pagination.next_url, ++count);
            }
        },
        error: function(jqXHR, textStatus, errorThrown) {
            //alert("Check you internet Connection");
            $("#log").val($("#log").val() + 'Error\n');
        }
    });
}​
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!