Last active
August 29, 2015 14:05
-
-
Save n9ti/74e9789b473bfb3b8b78 to your computer and use it in GitHub Desktop.
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'); | |
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