Created
December 22, 2014 04:08
-
-
Save serverwentdown/e106b6902acbbcc22995 to your computer and use it in GitHub Desktop.
Flickr API to obtain URLs. I'm not sure if this will break when it encounters a non-downloadable URL...
This file contains hidden or 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 setid = 72157629662278421; | |
var apikey = ""; | |
function get(url, cb) { | |
var req = https.request(url, function(res) { | |
if (res.statusCode == 200) { | |
var output = ""; | |
res.setEncoding('utf8'); | |
res.on('data', function (data) { | |
output += data; | |
}); | |
res.on('end', function () { | |
try { | |
output = JSON.parse(output); | |
} | |
catch (e) { | |
console.error("Non-JSON data returned. "); | |
return; | |
// get(name, cb); | |
} | |
cb(output); | |
}); | |
} | |
else { | |
console.error("Non-200 status code (" + res.statusCode + ") returned. "); | |
// get(name, cb); | |
} | |
}); | |
req.on('error', function(e) { | |
console.error("Can't send request. " + e.message); | |
}); | |
req.end(); | |
} | |
get("https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=" + apikey + "&photoset_id=72157600296941365&format=json&nojsoncallback=1", function (data) { | |
data.photoset.photo.forEach(function (item, index) { | |
get("https://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=" + apikey + "&photo_id=" + item.id + "&format=json&nojsoncallback=1", function (data) { | |
data.sizes.size.forEach(function (item, index) { | |
if (item.label == "Original") { | |
console.log(item.source); | |
} | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment