Last active
December 25, 2015 17:09
-
-
Save ifthenelse/7010955 to your computer and use it in GitHub Desktop.
Script that lists the images of a Facebook user, separated by album, using OpenGraph API. Just provide the target Facebook user id.
Original code by Nicola de Lazzari. Thanks to Enrico Vedovo.
This file contains 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> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Facebook batch photo download</title> | |
<meta name="description" content="This script will hopefully last longer than other apps. At lest until FB will change their damnd API again"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<h1>Facebook batch photo download</h1> | |
<p class="lead"> | |
This script will hopefully last longer than other apps. At lest until FB will change their damnd API again. | |
</p> | |
<div class="alert alert-success alert-dismissable"> | |
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> | |
Done. Now copy all the entries below on a <strong>list.txt<strong> file and use <a href="http://www.gnu.org/software/wget/" target="_blank">wget</a> to download them: | |
<code>wget -i list.txt</code> | |
</div> | |
<form role="form"> | |
<div class="form-group"> | |
<textarea class="form-control results" readonly="readonly" selectionStart="0" selectionEnd="100000" rows="20" cols="40"></textarea> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> | |
<script> | |
(function($){ | |
$(document).ready(function() { | |
var profile_id = ''; // Set here the target facebook user id | |
var limit = 400; // Set a high limit or facebook will retrieve just the first 25 | |
var $body = $('body'); | |
var $results_ct = $('textarea.results', $body); | |
var getAlbumImages = function() { | |
$(".alert-success").hide(); | |
$.get('https://graph.facebook.com/' + profile_id + '?fields=albums.fields(photos.limit(' + limit + ').fields(images),name)', function(response){ | |
if (!!response.albums && !!response.albums.data) { | |
for (var i = 0; i < response.albums.data.length; i++) { | |
var album = response.albums.data[i]; | |
if (!!album.name && !!album.id && !!album.photos && !!album.photos.data) { | |
$results_ct.val($results_ct.val() + "\n# listing images for album '" + album.name + "'"); | |
var validCount = 0; | |
for (var j = 0; j < album.photos.data.length; j++) { | |
var data = album.photos.data[j]; | |
if (!!data.images) { | |
var image = data.images[0]; | |
if (!!image.source) { | |
var imageurl = image.source; | |
$results_ct.val($results_ct.val() + '\n' + imageurl); | |
validCount++; | |
} | |
} | |
} | |
$results_ct.val($results_ct.val() + "\n# finished listing images for album '" + album.name + "'' (retrieved: " + validCount + "/" + album.photos.data.length + " items)\n# ---"); | |
} | |
} | |
$(".alert-success").show(); | |
} | |
}, 'json'); | |
}; | |
getAlbumImages(); | |
}); | |
})(jQuery); | |
</script> | |
</body> | |
</html> |
#4 Added fanciness and a responsive layout.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#3 Output will be printed as plain-text on the textarea, which is better than outputting on console. It would work even on smartphone and tablets that don't run developer tools.