Closed ckim16 closed 7 years ago
Don't set up new instances of the Flickr API every time the route gets called. It's not a constructor, but a full API object builder; call it once, and then bind the flickr
instance for use in your own API:
let flickr = false;
let flickrOptions = { api_key, secret };
Flickr.tokenOnly(flickrOptions, function(err, flickrObject) {
if (err) {
return console.error(err);
}
console.log('flickr', flickrObject);
flickr = flickrObject;
});
app.post('/', function(req, res) {
const { text } = req.body;
if (!flickr) {
return res.status(500).json({ error: 'flickr not ready yet' });
}
flickr.photos.search({
text,
content_type: 1,
per_page: 100,
page:1
}, function(err, result) {
console.log('result', result);
res.send(result);
});
});
I don't see an if (err) console.error(err)
in your code to check whether the api object creation succeeded or not, so at the very least you'll want to add that in.
Sweet it works now. I really appreciate it!!
no problem, good to hear it works now.
Hi,
I'm using react/redux and node.js/flickrapi to create a single webpage but I'm having trouble with fetching photos from flickrapi. I want to use tokenOnly method but I don't think it is going through it since I don't see any consoles that I put.
I do not see
flickr
console andresult
either. Trying to figure out what the problem but I am not making any progress.Has anyone had similar problem as mine and know how to resolve this?