Skip to content

Instantly share code, notes, and snippets.

@n9ti
Last active August 29, 2015 14:05
Show Gist options
  • Save n9ti/74e9789b473bfb3b8b78 to your computer and use it in GitHub Desktop.
Save n9ti/74e9789b473bfb3b8b78 to your computer and use it in GitHub Desktop.
Facebook Page Photos Downloader
var https = require('https');
var fs = require('fs');
var url = "https://graph.facebook.com/204379732996457/photos";
getGraphData(url);
function getGraphData(url) {
https.get(url, function(response) {
var result = '';
response.on('data', function(chunk) {
result += chunk;
});
response.on('end', function(chunk) {
var myJSON = JSON.parse(result);
for (var i = 0; i < myJSON.data.length; i++) {
downloadImage(myJSON.data[i].id, myJSON.data[i].source);
}
console.log(myJSON.data.length);
console.log(myJSON.paging.next);
if(myJSON.paging.next !== undefined){
getGraphData(myJSON.paging.next);
}
});
});
}
function downloadImage(id, url) {
var file = fs.createWriteStream('./images/' + id + '.jpg');
var request = https.get(url, function(response) {
response.pipe(file);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment