Last active
December 17, 2015 09:08
-
-
Save nguyenj/5584881 to your computer and use it in GitHub Desktop.
Random Flickr stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="photos" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img | |
vertical-align: bottom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment