Skip to content

Instantly share code, notes, and snippets.

@nguyenj
Last active December 17, 2015 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nguyenj/5584881 to your computer and use it in GitHub Desktop.
Save nguyenj/5584881 to your computer and use it in GitHub Desktop.
Random Flickr stream
<div id="photos" />
// http://www.flickr.com/services/api/explore/flickr.people.getPhotos
var apiUrl = "http://api.flickr.com/services/rest/?method=flickr.people.getPhotos&api_key={your_api_key}&user_id={your_user_id}&format=json&auth_token={the_authorization_token}&api_sig={api_signature}";
$.getJSON(apiUrl, function(data) {
var photoArr = [];
var randList = [];
var randNums;
photoArr = $.each(data.photos.photo, function(i, photo) {
return true
});
for (var i = 0; i < 25; i++) {
randList.push(i);
}
randList.sort(function (a, b) {
return Math.round(Math.random() * (25));
});
randNums = randList.splice(0, 25);
for ( var i = 0; i < randNums.length; i++) {
// http://www.flickr.com/services/api/misc.urls.html
$('<img />').attr('src', 'http://farm' + photoArr[randNums[i]].farm + '.staticflickr.com/' + photoArr[randNums[i]].server + '/' + photoArr[randNums[i]].id + '_' + photoArr[randNums[i]].secret + '_s.jpg').appendTo('#photos');
}
});
img
vertical-align: bottom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment