jQuery Combine Ajax Objects From Instagram API -
i have 2 problems. ultimate goal make request instagram , filter images tag. instagram doesn't allow more 33 images @ time right have ajax inside of another. first request gets images , checks if there more, if there more make request. here 2 problems.
#1 - can't combine these 2 objects 1. have tried think of or find online.
var new_data = $.extend({}, data, data2); and
$.extend(data, data2); are not working, gives me 1 of objects back
#2 - logic below flawed, because allow me 66 images max (2 request, 33 images each). need have ajax in loop of sort. i'm not sure how that.
var userid = '#######'; var token = '############'; var url = 'https://api.instagram.com/v1/users/' + userid + '/media/recent/?access_token=' + token + '&count=33'; $.ajax({ type: 'get', datatype: 'jsonp', cache: false, url: url, success: function(response){ var paging = response.pagination; var data = response.data; console.log(data); if(paging.hasownproperty('next_url')){ url = paging.next_url; $.ajax({ type: 'get', datatype: 'jsonp', cache: false, url: url, success: function(response2){ var data2 = response2.data; var new_data = $.extend({}, data, data2); } }); }else{ // no more images create image gallery } }, error: function(){ // error stuff } }); here sample of getting instagram

tested. works. try
var imagedata = []; $(function() { var url = 'https://api.instagram.com/v1/tags/smpspree/media/recent/?client_id=81e3d3f35c8a4438964001decaa5a31f&count=11'; getdata(url, function() { (var in imagedata) { console.log(imagedata[i]) } }); function getdata(url, callback){ $.ajax({ type: 'get', datatype: 'jsonp', cache: false, url: url, success: function(response){ console.log(response.data) imagedata = imagedata.concat(response.data) var paging = response.pagination; if (paging.hasownproperty('next_url')) { getdata(paging.next_url, callback) } else { callback.call(); } } }); } })
Comments
Post a Comment