Created
July 23, 2013 11:31
-
-
Save Cacodaimon/6061693 to your computer and use it in GitHub Desktop.
Quick and dirty Google Feed API example, fetching the first image of each feed item.
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Google Feed API JSONP Example displaying some Images - wwww.cacodaemon.de</title> | |
<script type="text/javascript"> | |
function processResults (response) { | |
var entries = response.responseData.feed.entries; | |
var images = document.getElementById('images'); | |
for (var i = entries.length - 1; i >= 0; i--) { | |
if (!entries[i].mediaGroups) { | |
continue; | |
} | |
var imageURL = entries[i].mediaGroups[0].contents[0].url; | |
var image = document.createElement('img'); | |
image.src = imageURL; | |
images.appendChild(image); | |
} | |
} | |
function doRequest (src, callback) { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = src; | |
if (callback) { | |
script.onload = callback; | |
} | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} | |
doRequest('https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http%3A//api.flickr.com/services/feeds/photos_public.gne%3Fid%3D17472213@N00%26lang%3Den-us%26format%3Drss_200&v=1.0&callback=processResults'); | |
</script> | |
</head> | |
<body> | |
<div id="images"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment