Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Search & paginate flicker photos for a given search filters and returns the collection of photos urls
var Client = require('node-rest-client').Client;
var _ = require("underscore");
var json2xls = require('json2xls');
var fs = require('fs');
//API Explorer : https://www.flickr.com/services/api/explore/flickr.photos.search
var flickr_api_endpoint = "https://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&nojsoncallback=1";
var flickerPhotos = [];
exports.handler = function (request, context) {
//1) Resolve input and execute REST calls
try {
var flickr_api_key = request.api_key;
var flickr_search_tags = request.search_tags;
var flickr_search_text = request.search_text;
var flickr_search_limit = request.search_limit;
var flickr_search_currentpage = request.search_currentpage;
flickr_api_endpoint = flickr_api_endpoint + "&api_key=" + flickr_api_key + "&tags=" + flickr_search_tags + "&text=" + flickr_search_text + "&per_page=" + flickr_search_limit + "&page=" + flickr_search_currentpage
console.log(flickr_api_endpoint);
var client = new Client();
client.registerMethod("flickrSearch", flickr_api_endpoint, "GET");
}
catch (e) {
context.fail("Something wrong in the input! please check. [" + e.message + "]");
}
//2) Process REST call response and send it back to the client.
var args = { headers: { "Content-Type": "application/json", "Cache-Control": "no-cache" } };
client.methods.flickrSearch(args,function (res, rawdata) {
try {
console.log("Length = [" + res.photos.photo.length + "]");
_.each(res.photos.photo, function (item, index, list) {
//console.log("http://farm" + item.farm + ".staticflickr.com/" + item.server + "/" + item.id + "_" + item.secret + "_b.jpg");
flickerPhotos[index] = "http://farm" + item.farm + ".staticflickr.com/" + item.server + "/" + item.id + "_" + item.secret + "_b.jpg";
});
context.succeed(flickerPhotos);
}
catch (e) {
context.fail(e.message);
}
}
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.