Flickr JavaScript SDK

The easiest way to talk to the Flickr API with node.js or a web browser. Officially supported by the Flickr Front End team.
Currently we cover the 10 most popular API methods (and some others) but we'll be adding support for more all the time.
Install
npm install flickr
What You Need First
You'll need to create an API key for your app, get a user to grant your app access to their data. Implementing that process and storing a user's oauth token and secret is your job. Here's a tool that walks you through that process quickly so you can start testing.
Implementation
Setup
var Flickr = require('flickr');
var flickr = new Flickr({
"apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"apiSecret": "xxxxxxxxxxxxxxxx",
"accessToken": "xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx",
"accessTokenSecret": "xxxxxxxxxxxxxxxx"
});
Responses
All responses are objects with two properties:
body
- containing the data requestedheaders
- any meta data returned in the headers from the API
Functions
Media
Uploading media
flickr
.request()
.media()
.post({
'photo': './path/to/photo.jpg'
})
.then(function (response) {
});
On the server the photo parameter should be a path to a local file. On the client it'll accept a File
object from a browser file field.
Fetching media
flickr
.request()
.media('22397283330')
.get()
.then(function (response) {
});
Searching for media
flickr
.request()
.media()
.search("puppies")
.get()
.then(function (response) {
});
People
Person's Media
flickr
.request()
.people("40575690@N00")
.media()
.get()
.then(function (response) {
});
Person's Favorites
flickr
.request()
.people("40575690@N00")
.favorites()
.media()
.get()
.then(function (response) {
});
Person's Albums
flickr
.request()
.people("40575690@N00")
.albums()
.get()
.then(function (response) {
});
Contexts
flickrSDK
.request()
.media('22397283330')
.context(5)
.album('72157657634723246')
.get()
.then(function (response) {
});
Other contexts available:
flickr.request().media(*photoID*).context(5).photolist(*photolistHash*)
flickr.request().media(*photoID*).context(5).photosOf(*personID*)
flickr.request().media(*photoID*).context(5).groupPool(*groupID*)
flickr.request().media(*photoID*).context(5).sharedEntity(*guestpassID*, *guestpassOwner*)
flickr.request().media(*photoID*).context(5).gallery(*galleryID*)
flickr.request().media(*photoID*).context(5).photostream()
flickr.request().media(*photoID*).context(5).favorites(*personID*)
Groups
flickr
.request()
.groups('22397283330')
.get()
.then(function (response) {
});
Group Media
flickr
.request()
.groups('22397283330')
.media()
.get()
.then(function (response) {
});
Group Discussions
flickr
.request()
.groups('22397283330')
.discussions()
.get()
.then(function (response) {
});
Album Media
flickr
.request()
.albums('22397283330')
.media()
.get()
.then(function (response) {
});
Gallery Media
flickr
.request()
.galleries('22397283330')
.media()
.get()
.then(function (response) {
});
Handing Over Extra Parameters
Most methods accept a number of parameters to modify the response. Page and per page parameters are a common example.
You can pass arbitrary as an object argument into the verb method like this:
flickr
.request()
.people("40575690@N00")
.media()
.get({
page: 2,
per_page: 20
})
.then(function (response) {
});
Here's a more advanced search example:
flickr
.request()
.media()
.search("puppies")
.get({
contacts: 'all',
media: 'photos'
sort: 'date-taken-desc'
})
.then(function (response) {
});
Handling Errors
All API calls return a Promise.
To handle an error just a provide a handler like this:
flickr
.request()
.people("🦄")
.media()
.get()
.then(function (response) {
}, function (err) {
});
Compatibility and Browser Support
- Latest Chrome
- Latest Safari
- Latest Firefox
- Latest Mobile Safari
- IE 10+ for sure, maybe 9 too
- Node 0.10+
License
Code licensed under the MIT license. See LICENSE file for terms.