I've been tinkering around with pagination via the Instagram API; however, I'm a bit stuck as to how to go about storing returned data through my recursive calls.
I would like to store all of the item links in an array, but my current method returns an empty array.
Any help would be much appreciated!
$(document).ready(function() {
$('#fetch_followers').click(function() {
pollInstagram('https://api.instagram.com/v1/users/3/media/recent/?callback=?&min_timestamp=1388563200&max_timestamp=1420099200&access_token={access_token}', 33);
});
});
function pollInstagram(next_url, count) {
var collected_objs = []; // Array to collect links (urls)
$.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');
console.log("****************************");
console.log("This " + JSON.stringify(item.link));
console.log("****************************");
$('#target').append('<div id="likes_info"><a href="'+item.link+'"><img src="'+item.images.thumbnail.url+'"/></a>'+"<p><span>"+item.likes.count+"</span></p></div>");
collected_objs.push(item.link); // Adding urls to collected_objs -- Not Working
});
$("#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 ) {
var n_url=data.pagination.next_url + "&callback=?";
pollInstagram(n_url, ++count);
}
},
error: function(jqXHR, textStatus, errorThrown) {
//alert("Check you internet Connection");
$("#log").val($("#log").val() + 'Error\n');
}
});
}
Aucun commentaire:
Enregistrer un commentaire