I know, I know, facebook has a function to download a album (if you own it afaik). But as far I have experienced it so far, this function is damn buggy and slow, especially if you want to download all (public) albums of a page (where you are moderator).

But why would I want to download all albums you might ask? Because I had to/wanted to create a wordpress website for someone and all photos should be migriated to the website. So I started to download the albums via the 3 dot in the corner and download, but it took Facebook about 3 minutes to provide the download. Via your notifications ಠ_ಠ. And after downloading I got a ZIP-achive, of some kilobyte, containing the txt-files named no-content.txt (╯°□°)╯︵ ┻━┻ .

So than, a script… because it’s less buggy and downloading about 50 albums this way is kinda anoying.

<?php

$api="YOURFACEBOOKAPIKEY";
$page="diehuetteboxdorf"; // replace with the page which albums you want to download

$albums_url = "https://graph.facebook.com/v3.1/".$page."/albums?fields=description%2Cname%2Ccreated_time%2Cphoto_count&limit=100&access_token=".$api;

$albums = json_decode(file_get_contents($albums_url));

foreach($albums->data as $album) {
	echo "Downloading '".$album->name."' (".$album->photo_count.")\n";
	$content = json_decode(file_get_contents("https://graph.facebook.com/v3.1/".$album->id."/photos?fields=images&limit=100&access_token=".$api));
//	print_r($album);
//	print_r($content);
	$folder = date("d-m-Y",strtotime($album->created_time));
	if(substr($folder, 0, 4) !== "2018" && substr($folder, 0, 4) !== "2019"){
		continue;
	}
	mkdir($folder);
	file_put_contents($folder."/description.txt", $album->description);
	file_put_contents($folder."/title.txt", $album->name);
	$i = 0;
	$next = "https://graph.facebook.com/v3.1/".$album->id."/photos?fields=images&limit=100&access_token=".$api;
	do{
		$content = json_decode(file_get_contents($next));
		foreach($content->data as $image) {
			echo "  ".$i++.": ".$image->images[0]->source."\n";
			file_put_contents($folder."/".sha1(random_bytes(16)).".jpg", fopen($image->images[0]->source, 'r'));
		}
//		$content = json_decode(file_get_contents($content->paging->next));
		$next = $content->paging->next;
	}while(isset($content->paging->next));

}
//print_r($albums);

The script retrives the album information from the anoying AF Facebook Graph API. You need an API Key, which can be retrived via the Graph API Explorer. There you can also tinker around with available options to filter albums or pictures

Facebook API Explorer screenshot


Bennet Becker

22 y/o it specialist, computer sience student, hobby programmer and hobby photographer living in Germany