Created
August 31, 2014 18:45
-
-
Save n9ti/826ad6ffb55a5dc21e61 to your computer and use it in GitHub Desktop.
Simple Facebook Page Photos Downloader
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
var https = require('https'); | |
var fs = require('fs'); | |
https.get("https://graph.facebook.com/204379732996457/photos", function(response) { | |
var result = ''; | |
response.on('data', function (chunk) { | |
result += chunk; | |
}); | |
response.on('end', function (chunk) { | |
var photos = JSON.parse(result); | |
for(var i=0;i<photos.data.length;i++) { | |
var photo = photos.data[i]; | |
console.log(photo.id); | |
downloadImage(photo.id, photo.source); | |
} | |
}); | |
}); | |
function downloadImage(id, url) { | |
var file = fs.createWriteStream(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