How to download a Facebook album
A friend came to me, saying that he wanted to download a photo album off of Facebook. He said he had tried different solutions on the internet, but they didn’t work. I decided to help him out and hack together my own solution, and this is the end result.
The first thing I needed to do was to find the URLs of all the photos. I wrote this quick JavaScript snippet that does that. To get the URLs, I navigate to the page with the album, open the console (Ctrl-Shift-J in Chrome), and paste in this code:
console.log(Array.prototype.map.call(document.querySelectorAll('table.uiGrid.fbPhotosGrid a.uiMediaThumb'), function (a) {
// The URL to the photo is within the 'ajaxify' attribute of each thumbnail link
// Construct an 'a' element to parse the query string
var b = document.createElement('a');
b.href = a.getAttribute('ajaxify');
var params = b.search.replace(/^\?/, '').split('&');
for (var i = 0; i < params.length; i++)
if (params[i].indexOf('src') == 0)
return unescape(params[i].split('=')[1]);
return '';
}).join('\n'));
I hit enter and get a list of URLs:

Now that I have the URLs, I pasted that in a file named urls. I made a directory named album and then wrote this simple PHP script that downloads the files and then compresses them into a ZIP file.
<?php
$fp = fopen('urls', 'r');
$i = 1;
while ($url = fgets($fp)) {
file_put_contents("album/$i.jpg", file_get_contents($url));
echo "Downloaded $i\n";
$i++;
}
shell_exec('zip album.zip album/*');
And now, I have a file named album.zip with all the photos!






Hi Casey,
Just wanted to say that you made a great job in this post! I could download an entire album even with the first script and then using jDownloader to do the direct downloads. Also, I noticed that this doesn’t download the photos in their best quality as if you would’ve done it by the manual Download option.. that’s a shame :( But nevertheless this is a very nice script.
Thanks!