-
-
Save iandexter/115932 to your computer and use it in GitHub Desktop.
Get random photo from Flickr Interestingness
This file contains hidden or 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
function loadJSON(url) { | |
var headElt = document.getElementsByTagName('head')[0]; | |
var jsonScript = document.createElement('script'); | |
jsonScript.type = "text/javascript"; | |
jsonScript.src = url; | |
headElt.appendChild(jsonScript); | |
} | |
var flickAPIkey = "your API key goes here"; | |
loadJSON("http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&api_key=" + flickrAPIkey + "&per_page=100&page=1&format=json"); | |
function jsonFlickrApi(obj) { | |
var i = Math.floor(Math.random()*100); | |
var photo = obj.photos.photo[i]; | |
var url = "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/"+ photo.id + "_" + photo.secret + ".jpg"; | |
var link = document.createElement('a'); | |
link.href = "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id; | |
link.target = "_none"; | |
var image = document.createElement('img'); | |
image.setAttribute('src',url); | |
image.setAttribute('title',photo.title); | |
link.appendChild(image); | |
document.getElementById('flickphoto').removeChild(document.getElementById('rotator')); | |
document.getElementById('flickphoto').appendChild(link); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment