I’ve written a simple little PHP program to grab random thumbnails from your public Facebook photo albums. Why? Because I was tired of maintaining multiple photo albums (one for my personal site, one for Facebook, one for MySpace, one for flickr, etc) that all had the same pictures. This at least lets you include your Facebook photos on your personal website or blog. I’m releasing it under GPL licensing: you’re free to use it, copy it, distribute it, all I ask is that if you use it you comment and let me know, and if you improve upon it let me know and I’ll post your revisions here. There are many bugs so I’m sure some of you will want to fix them :-)
I used a PHP HTML parser by Carlos Jordao available here.
TODO:
`
<?
/*
// Number of photos to display. Changing this value won’t affect speed that much.
$photos = 3;
// Number of albums to use.
// If you’re having speed and/or timeout issues, try fewer albums.
$albums = 2;
// Photo size, in pixels.
$width = 130; // Isn’t used right now, but it could be by editing getPage function.
$height = 97;
// Base public URLs for the Facebook photo albums.
// Make sure your URL doesn’t have &page=# in it –
// use the URL listed as public at the bottom of your album page.
$urlArray[0] = “http://rose-hulman.facebook.com/album.php?aid=2000544&l=56720&id=29201812”;
$urlArray[1] = “http://rose-hulman.facebook.com/album.php?aid=2007166&l=7cbc8&id=29201812”;
$urlArray[2] = “http://rose-hulman.facebook.com/album.php?aid=2006808&l=3df4a&id=29201812”;
$urlArray[3] = “http://rose-hulman.facebook.com/album.php?aid=2005852&l=e4d78&id=29201812”;
$urlArray[4] = “http://rose-hulman.facebook.com/album.php?aid=2003978&l=49c4b&id=29201812”;
$urlArray[5] = “http://rose-hulman.facebook.com/album.php?aid=2004843&l=0fe23&id=29201812”;
$urlArray[6] = “http://rose-hulman.facebook.com/album.php?aid=2004733&l=235f8&id=29201812”;
$urlArray[7] = “http://rose-hulman.facebook.com/album.php?aid=2000556&l=93830&id=29201812”;
$urlArray[0] = “http://rose-hulman.facebook.com/album.php?aid=2004139&l=8f958&id=29201812”;
$urlArray[1] = “http://rose-hulman.facebook.com/album.php?aid=2004138&l=ee2cc&id=29201812”;
$urlArray[2] = “http://rose-hulman.facebook.com/album.php?aid=2004137&l=2273a&id=29201812”;
$urlArray[3] = “http://rose-hulman.facebook.com/album.php?aid=2004135&l=ff7f8&id=29201812”;
$urlArray[4] = “http://rose-hulman.facebook.com/album.php?aid=2004134&l=e6467&id=29201812”;
$urlArray[13] = “http://rose-hulman.facebook.com/album.php?aid=2001024&l=12fa1&id=29201812”;
$urlArray[14] = “http://rose-hulman.facebook.com/album.php?aid=2000622&l=f4a1c&id=29201812”;
$urlArray[15] = “http://rose-hulman.facebook.com/album.php?aid=2000614&l=c2b10&id=29201812”;
$urlArray[16] = “http://rose-hulman.facebook.com/album.php?aid=2000613&l=5f18a&id=29201812”;
$urlArray[17] = “http://rose-hulman.facebook.com/album.php?aid=2000608&l=a3f27&id=29201812”;
$urlArray[18] = “http://rose-hulman.facebook.com/album.php?aid=2000607&l=ae91e&id=29201812”;
$urlArray[19] = “http://rose-hulman.facebook.com/album.php?aid=2000606&l=b9f49&id=29201812”;
$urlArray[20] = “http://rose-hulman.facebook.com/album.php?aid=2000604&l=1a64d&id=29201812”;
$urlArray[21] = “http://rose-hulman.facebook.com/album.php?aid=2000603&l=ffa4e&id=29201812”;
$urlArray[22] = “http://rose-hulman.facebook.com/album.php?aid=2000602&l=5a86c&id=29201812”;
$urlArray[23] = “http://rose-hulman.facebook.com/album.php?aid=2000559&l=6604a&id=29201812”;
$urlArray[24] = “http://rose-hulman.facebook.com/album.php?aid=2000555&l=5e6ef&id=29201812”;
///////////////////////////////////////////
// Set environment – Facebook only allows Mozilla, IE, Opera compatible
$userAgent=”Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)”;
@ini_set(‘user_agent’, $userAgent);
@ini_set(‘display_errors’,”off”); // Yeah, I know this is bad. But it’s better than bugging out and screwing up someone’s page.
// Global fields
$pageNumber = 1;
$done = false;
$imgArray = array(); // Stores all image HTML
// Main Program Starts Here
$albumArray = albumRandomizer($albums + 1,$urlArray); // Albums to be used this time around
foreach ($albumArray as $url) {
while (!$done) {
// Grab the page
$imgArray = getPage($url,$pageNumber,$imgArray,$width,$height);
$pageNumber++;
// Check for another page
$continue = anotherPage($url,$pageNumber);
if (!$continue) {
$done = true;
}
}
// Reset
$done = false;
$pageNumber = 1;
}
// Pick some random photos
$finalArray = albumRandomizer($photos,$imgArray); // Stores just the images to be printed
// Print images – Edit this to make your photos display how you want them to.
foreach ($finalArray as $picture) {
echo $picture;
}
///////////////////////////////////////////
/*
do {
$s_tagTokOption = strtoupper(strtok($s_tagOption[1], “=”));
$s_tagTokValue = trim(strtok(“=”));
$a_html[$s_tagName][$i_arrayCounter][$s_tagTokOption] =
$s_tagTokValue;
$b_boolOptions = is_array(($s_tagOption=each($a_tag))) &&
$s_tagOption[1];
} while( $b_boolOptions );
}
}
return $a_html;
}
?>
`
Reading:
Social