/flickr-backend-example

An API in NodeJS/Express for serving Flick images

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

flickr-backend-example

A proxy in NodeJS/Express that make calls to the Flickr API and avoids the complexity of the authentication process.

Who is this project for?

If you want to call the Flickr API and forget the authentication process, that project will be useful. With this proxy you can call to:

  • Flickr API methods that don't need authentication.
  • Flickr API methods that need authentication with read privileges.

Note: Methods that need authentication with write privileges are not implemented.

How to install/configure the project?

Installation

Just:

$ git clone https://github.com/aaronplanell/flickr-backend-example.git
$ cd flickr-backend-example
$ npm install

Obviously, the last line can be replaced by:

$ yarn install

Configuration

Just open the file src/constants.js and replace the consumer key/secret:

export const FLICKR_CONSUMER_KEY = 'b7718b2dc66dee760a0f66c56f507434';
export const FLICKR_CONSUMER_SECRET = 'topSecret';

You can obtain the consumer key/secret in the web of Flickr.

NOTE: Never publish your consumer key/secret in Github or other site. I published mine because is a fake account.

How to run the project?

First of all run:

$ npm start

Or:

$ yarn start

You will see a message like this:

yarn start v0.21.3
$ babel-node src/index.js --presets es2015,stage-2
Express server listening on port 3000
First of all, you must validate the application opening: http://127.0.0.1:3000/

Open your browser and access to the URL http://127.0.0.1:3000/. The main page will be redirected you to the Flickr API page of authorization. Accept making click into the blue button. After that, you will be redirected to the previous local page and you will see this message:

Well... You're connected. You can work with the API :D

Your Flickr API Proxy will be running.

How it works?

When the proxy is ready you will see at the console the list of available methods:

Checking available methods:
- Adding method flickr.auth.getToken (no authentication needed).
- Adding method flickr.activity.userComments (authentication needed with read permissions).
- Adding method flickr.auth.getFrob (no authentication needed).
- Adding method flickr.auth.oauth.getAccessToken (no authentication needed).
- Adding method flickr.activity.userPhotos (authentication needed with read permissions).
- Etc.

If, for instance, you want to search the photos of the user 148575064@N08 just call:

http://127.0.0.1:3000/flickr.photos.search?user_id=148575064@N08

The parameters of each method are the same that in the original Flickr API but with an exception: you don't need to pass the parameter api_key because you are autenthicated.

Which methods of Flickr API are available?

This proxy implements those methods that:

  • Don't need authentication.
  • Need authentication with read privileges.

Methods with write privileges are not allowed.

This is the full list:

How to test the project?

Once you have your server running and authorized, because it uses integration tests, open another terminal and just run:

npm run test

Or:

yarn run test

You will find all the tests in the tests folder. For every method its test checks:

  • The status returned is OK.
  • Its snapshot.

It uses Jest technology :)

Contributing

This project uses grant-express & purest. Thanks to @simov for both projects.

License

GPL (GNU GENERAL PUBLIC LICENSE)