Created
September 10, 2012 05:28
-
-
Save sfalquier/3689051 to your computer and use it in GitHub Desktop.
Radom photo picked up in a Facebook Page albums
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
<script type="text/javascript"> | |
window.onload = function main() | |
{ | |
var script = document.createElement("script"); | |
script.src = "https://graph.facebook.com/platform/albums?callback=getalbum"; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
function getalbum(facebook) { | |
var randomalbum = Math.floor(Math.random()*(facebook.data.length)); | |
try { | |
var albumid = facebook.data[randomalbum].id; | |
if(facebook.data[randomalbum].type!="normal") { | |
albumid = facebook.data[0].id; | |
} | |
} catch (error) { | |
} | |
var script = document.createElement("script"); | |
script.src = "https://graph.facebook.com/"+albumid+"/photos?limit=500&callback=getimage"; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
} | |
function getimage(facebook) | |
{ | |
var randomimg = Math.floor(Math.random()*(facebook.data.length)); | |
try { | |
var link = document.createElement("a"); | |
link.href = facebook.data[randomimg].link; | |
var img = document.createElement("img"); | |
for (var i = 0; i < facebook.data[randomimg].images.length; i++) { | |
if(facebook.data[randomimg].images[i].width==320) { | |
img.src = facebook.data[randomimg].images[i].source; | |
} | |
} | |
img.alt = "no image"; | |
img.title = facebook.data[randomimg].name; | |
img.width = 235; | |
link.appendChild(img); | |
document.getElementById("fb_image").appendChild(link); | |
} catch (error) { | |
} | |
} | |
</script> | |
<p id="fb_image" style="text-align:center;"></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment