flickr-sdk
Almost certainly the best Flickr API client in the world for node and the browser
Install
$ npm install flickr-sdk
Usage
flickr-sdk is based on superagent and all methods that make API calls will return a superagent Request instance configured for the request. This means that you can do anything with Flickr requests that you can do with superagent.
The Flickr API is divided into several services:
- The REST API service, which provides access to Flickr data
- The OAuth service, which authenticates users via OAuth 1.0
- The Feeds service, which provides feeds of public Flickr data
- The Upload service, where you can upload photos!
- The Replace service, where you can replace photos you previously uploaded
Example
const Flickr = require('flickr-sdk');
const flickr = new Flickr(process.env.FLICKR_API_KEY);
const { body } = await flickr.photos.getInfo({
photo_id: 'your photo id here',
})
Browser Usage
Since OAuth 1.0 requires your application's key and secret to sign requests, flickr-sdk does not support this authentication method in the browser. Upload, Replace, and REST API calls that require authentication will not work without a valid OAuth signature. You can still use flickr-sdk to call REST API methods that don't require authentication or to get public feeds.
flickr-sdk has been tested with browserify but should work with other client-side module bundlers like webpack and rollup. If you need a standalone browser-ready version of flickr-sdk, each release on npm will contain a browserified version of this module at node_modules/flickr-sdk/flickr-sdk.js
. It is not minified.
Flickr
All of the REST API methods are available on the Flickr prototype. Each method accepts a single parameter which is an optional hash of arguments. Refer to the REST API docs for the full list of methods and their supported arguments.
Kind: global class
- Flickr
- new Flickr(auth)
- .OAuth
- new OAuth(consumerKey, consumerSecret)
- instance
- .request(oauthCallback) ⇒
Request
- .authorizeUrl(requestToken, [perms]) ⇒
String
- .verify(oauthToken, oauthVerifier, tokenSecret) ⇒
Request
- .plugin(oauthToken, oauthTokenSecret) ⇒
function
- .request(oauthCallback) ⇒
- static
- .Upload ⇐
Request
- .Replace ⇐
Request
- .Feeds
- new Feeds([args])
- .publicPhotos([args]) ⇒
Request
- .friendsPhotos(args) ⇒
Request
- .favePhotos(args) ⇒
Request
- .groupDiscussions(args) ⇒
Request
- .groupPool(args) ⇒
Request
- .forum([args]) ⇒
Request
- .recentComments(args) ⇒
Request
new Flickr(auth)
Creates a new Flickr REST API client.
You must pass a superagent plugin or your API key as the first parameter. For methods that don't require authentication, you can simply provide your API key. For methods that do require authentication, use the OAuth plugin.
Param | Type | Description |
---|---|---|
auth | function | String |
An authentication plugin function or an API key |
Example (Get info about a public photo with your API key)
var flickr = new Flickr(process.env.FLICKR_API_KEY);
flickr.photos.getInfo({
photo_id: 25825763 // sorry, @dokas
}).then(function (res) {
console.log('yay!', res.body);
}).catch(function (err) {
console.error('bonk', err);
});
Example (Searching for public photos with your API key)
var flickr = new Flickr(process.env.FLICKR_API_KEY);
flickr.photos.search({
text: 'doggo'
}).then(function (res) {
console.log('yay!', res.body);
}).catch(function (err) {
console.error('bonk', err);
});
Example (Authenticate as a user with the OAuth plugin)
var flickr = new Flickr(Flickr.OAuth.createPlugin(
process.env.FLICKR_CONSUMER_KEY,
process.env.FLICKR_CONSUMER_SECRET,
process.env.FLICKR_OAUTH_TOKEN,
process.env.FLICKR_OAUTH_TOKEN_SECRET
));
flickr.test.login().then(function (res) {
console.log('yay!', res.body);
}).catch(function (err) {
console.error('bonk', err);
});
Flickr.OAuth
Kind: static class of Flickr
- .OAuth
- new OAuth(consumerKey, consumerSecret)
- instance
- .request(oauthCallback) ⇒
Request
- .authorizeUrl(requestToken, [perms]) ⇒
String
- .verify(oauthToken, oauthVerifier, tokenSecret) ⇒
Request
- .plugin(oauthToken, oauthTokenSecret) ⇒
function
- .request(oauthCallback) ⇒
- static
new OAuth(consumerKey, consumerSecret)
Creates a new OAuth service instance. You can use this service to request and validate OAuth tokens, as well as generate an auth plugin suitable for use with the REST and Upload services.
You need to register an application
to obtain your consumerKey
and consumerSecret
.
OAuth 1.0 requires your consumer secret to sign calls, and you should never expose secrets to the browser.
Param | Type | Description |
---|---|---|
consumerKey | String |
The application's API key |
consumerSecret | String |
The application's API secret |
Example
var oauth = new Flickr.OAuth(
process.env.FLICKR_CONSUMER_KEY,
process.env.FLICKR_CONSUMER_SECRET
);
Request
oAuth.request(oauthCallback) ⇒ Get a Request Token using the consumer key.
Kind: instance method of OAuth
See
- https://github.com/visionmedia/superagent
- https://www.flickr.com/services/api/auth.oauth.html#request_token
Param | Type | Description |
---|---|---|
oauthCallback | String |
Your application's OAuth callback URL |
Example
oauth.request('http://localhost:3000/oauth/callback').then(function (res) {
console.log('yay!', res);
}).catch(function (err) {
console.error('bonk', err);
});
String
oAuth.authorizeUrl(requestToken, [perms]) ⇒ Returns the authorization url for requestToken
. You may also pass
the perms
your app is requesting as read
(the default), write
,
or delete
. Your application should redirect the user here to ask
them to verify your request token.
Kind: instance method of OAuth
See: https://www.flickr.com/services/api/auth.oauth.html#authorization
Param | Type | Default | Description |
---|---|---|---|
requestToken | String |
The OAuth request token | |
[perms] | String |
read |
Permission level, may be "read", "write" or "delete" |
Example
var url = oauth.authorizeUrl(requestToken); // "https://www.flickr.com/services/oauth..."
res.setHeader("Location", url);
res.statusCode = 302;
res.end();
Request
oAuth.verify(oauthToken, oauthVerifier, tokenSecret) ⇒ Verify an OAuth token using the verifier and token secret. If your user has indeed verified your request token, you will receive an OAuth token and secret back, as well as some very basic profile information. You can now use this token and secret to make calls to the REST API.
Kind: instance method of OAuth
See
- https://github.com/visionmedia/superagent
- https://www.flickr.com/services/api/auth.oauth.html#access_token
Param | Type | Description |
---|---|---|
oauthToken | String |
The OAuth token to verify |
oauthVerifier | String |
The OAuth token verifier string you received from the callback |
tokenSecret | String |
The OAuth token secret |
Example
oauth.verify(oauthToken, oauthVerifier, tokenSecret).then(function (res) {
console.log('oauth token:', res.body.oauth_token);
console.log('oauth token secret:', res.body.oauth_token_secret);
}).catch(function (err) {
console.log('bonk', err);
});
function
oAuth.plugin(oauthToken, oauthTokenSecret) ⇒ Returns an oauth plugin for this consumer key and secret.
Kind: instance method of OAuth
Param | Type | Description |
---|---|---|
oauthToken | String |
The OAuth token |
oauthTokenSecret | String |
The OAuth token secret |
Example
var flickr = new Flickr(oauth.plugin(
oauthToken,
oauthTokenSecret
));
function
OAuth.createPlugin(consumerKey, consumerSecret, oauthToken, oauthTokenSecret) ⇒ Returns an oauth plugin for this consumer key, consumer secret, oauth token and oauth token secret,
Kind: static method of OAuth
Param | Type | Description |
---|---|---|
consumerKey | String |
The application's API key |
consumerSecret | String |
The application's API secret |
oauthToken | String |
The OAuth token |
oauthTokenSecret | String |
The OAuth token secret |
Example
var flickr = new Flickr(Flickr.OAuth.createPlugin(
process.env.FLICKR_CONSUMER_KEY,
process.env.FLICKR_CONSUMER_SECRET,
process.env.FLICKR_OAUTH_TOKEN,
process.env.FLICKR_OAUTH_TOKEN_SECRET
));
Request
Flickr.Upload ⇐ Kind: static class of Flickr
Extends: Request
See: https://www.flickr.com/services/api/upload.api.html
new Upload(auth, file, [args])
Creates a new Upload service instance. Since the Upload API only does one thing (upload files), an Upload instance is simply a Request subclass.
The Upload endpoint requires authentication. You should pass a configured instance of the OAuth plugin to upload photos on behalf of another user.
Param | Type |
---|---|
auth | function |
file | String | fs.ReadStream | Buffer |
[args] | Object |
Example
var upload = new Flickr.Upload(auth, 'upload.png', {
title: 'Works on MY machine!'
});
upload.then(function (res) {
console.log('yay!', res.body);
}).catch(function (err) {
console.error('bonk', err);
});
Request
Flickr.Replace ⇐ Kind: static class of Flickr
Extends: Request
See: https://www.flickr.com/services/api/replace.api.html
new Replace(auth, photoID, file, [args])
Creates a new Replace service instance. Since the Replace API only does one thing (replace files), an Replace instance is simply a Request subclass.
The Replace endpoint requires authentication. You should pass a configured instance of the OAuth plugin to replace photos on behalf of another user.
Param | Type | Description |
---|---|---|
auth | function |
|
photoID | Number | String |
The ID of the photo to replace |
file | String | fs.ReadStream | Buffer |
|
[args] | Object |
Example
var replace = new Flickr.Replace(auth, 41234567890, 'replace.png', {
title: 'Now in pink!'
});
replace.then(function (res) {
console.log('yay!', res.body);
}).catch(function (err) {
console.error('bonk', err);
});
Flickr.Feeds
Kind: static class of Flickr
- .Feeds
- new Feeds([args])
- .publicPhotos([args]) ⇒
Request
- .friendsPhotos(args) ⇒
Request
- .favePhotos(args) ⇒
Request
- .groupDiscussions(args) ⇒
Request
- .groupPool(args) ⇒
Request
- .forum([args]) ⇒
Request
- .recentComments(args) ⇒
Request
new Feeds([args])
Creates a new Feeds service instance. You can use this instance to explore and retrieve public Flickr API data.
Param | Type | Default | Description |
---|---|---|---|
[args] | Object |
Arguments that will be passed along with every feed request | |
[args.format] | String |
json |
The feed response format |
[args.lang] | String |
en-us |
The language to request for the feed |
Example
var feeds = new Flickr.Feeds();
Request
feeds.publicPhotos([args]) ⇒ Returns a list of public content matching some criteria.
Kind: instance method of Feeds
See: https://www.flickr.com/services/feeds/docs/photos_public/
Param | Type |
---|---|
[args] | Object |
Request
feeds.friendsPhotos(args) ⇒ Returns a list of public content from the contacts, friends & family of a given person.
Kind: instance method of Feeds
See: https://www.flickr.com/services/feeds/docs/photos_friends/
Param | Type | Description |
---|---|---|
args | Object |
|
args.user_id | Number | String |
The user ID of the user to fetch friends' photos and videos for. |
Request
feeds.favePhotos(args) ⇒ Returns a list of public favorites for a given user.
Kind: instance method of Feeds
See: https://www.flickr.com/services/feeds/docs/photos_faves/
Param | Type | Description |
---|---|---|
args | Object |
|
args.id | Number | String |
A single user ID. This specifies a user to fetch for. |
Request
feeds.groupDiscussions(args) ⇒ Returns a list of recent discussions in a given group.
Kind: instance method of Feeds
See: https://www.flickr.com/services/feeds/docs/groups_discuss/
Param | Type | Description |
---|---|---|
args | Object |
|
args.id | Number |
The ID of the group to fetch discussions for. |
Request
feeds.groupPool(args) ⇒ Returns a list of things recently added to the pool of a given group.
Kind: instance method of Feeds
See: https://www.flickr.com/services/feeds/docs/groups_pool/
Param | Type | Description |
---|---|---|
args | Object |
|
args.id | Number |
The ID of the group to fetch for. |
Request
feeds.forum([args]) ⇒ Returns a list of recent topics from the forum.
Kind: instance method of Feeds
See: https://www.flickr.com/services/feeds/docs/forums/
Param | Type |
---|---|
[args] | Object |
Request
feeds.recentComments(args) ⇒ Returns a list of recent comments that have been commented on by a given person.
Kind: instance method of Feeds
See: https://www.flickr.com/services/feeds/docs/photos_comments/
Param | Type | Description |
---|---|---|
args | Object |
|
args.user_id | Number | String |
The user ID to fetch recent comments for. |
License
Code licensed under the MIT license. See LICENSE file for terms.