Skip to content

Instantly share code, notes, and snippets.

@serverwentdown
Created December 22, 2014 04:08
Show Gist options
  • Save serverwentdown/e106b6902acbbcc22995 to your computer and use it in GitHub Desktop.
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...
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