I'm trying to pull photos from an album (timeline) on Facebook and insert them into a list on a website but it's not grabbing all the photos.
I am using the ?limit=xxx in the URL to grab more than the first page but it still isn't working. Should I be using the paging ids and if so, what would be the syntax?
$.getJSON('https://graph.facebook.com/616894958361877/photos?limit=500&callback=?',function(json){
$.each(json.data,function(){
$('<li></li>').append('<span class="thumb" style="background: url(' + this.images[1].source + ') center center no-repeat; background-size: cover;"><a href=' + this.images[0].source + ' rel="gallery"></a></span>').appendTo('#timeline');
});
});
This is the public facebook album in question: https://www.facebook.com/media/set/?set=a.616319455086094.1073741826.293095517408491&type=3
Looks like the limit is 100
. Check the graph explorer for that. The limit 500 is overridden with 100 and the api return pagination details.
Also in the above code snippet, while accessing images
array there can be cases where images which might not have images[1]
so try to handle that. Something like this
((photo.images[1]) ? photo.images[1].source: ''
In this demo http://jsbin.com/nalusu/1/ you can see that the api returns 100 results.