Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Easy peasy facebook client for connect

branch: master
Octocat-spinner-32 lib Avoid callback firing twice on error September 09, 2011
Octocat-spinner-32 tests fixed tests June 06, 2011
Octocat-spinner-32 .gitignore 1.0.0 June 06, 2011
Octocat-spinner-32 LICENSE Added license July 31, 2013
Octocat-spinner-32 Makefile 1.0.0 June 06, 2011
Octocat-spinner-32 Readme.md Added license July 31, 2013
Octocat-spinner-32 index.js 0.0.2, improved npm and docs November 07, 2010
Octocat-spinner-32 package.json double callback, OMG! September 09, 2011
Readme.md

facebook-js

Minimalistic facebook API client

npm install facebook-js

Usage

facebook-js has just three methods.

  • getAuthorizeUrl(options): Returns the authorize url.
  • getAccessToken(key, secret, code, redirect_uri, callback[error, access_token, refresh_token]): Uses oAuth module to callback the access_token.
  • apiCall(http_method, path, params, callback[error, response, body]): Does a call to facebook graph API and callbacks when its done.

Example using express.js

var express = require('express')
  , fb = require('facebook-js')
  , app = express.createServer(
      express.bodyParser()
    , express.cookieParser()
    , express.session({ secret: 'some secret' })
    );

app.get('/', function (req, res) {
  res.redirect(fb.getAuthorizeUrl({
    client_id: 'appID',
    redirect_uri: 'http://yourhost.com:3003/auth',
    scope: 'offline_access,publish_stream'
  }));
});

app.get('/auth', function (req, res) {
  fb.getAccessToken('appID', 'appSecret', req.param('code'), 'http://yourhost.com:3003/auth'}, function (error, access_token, refresh_token) {
    res.render('client', {access_token: access_token, refresh_token: refresh_token});
  });
});

app.post('/message', function (req, res) {
  fb.apiCall('POST', '/me/feed',
    {access_token: req.param('access_token'), message: req.param('message')},
    function (error, response, body) {
      res.render('done', {body: body});
    }
  );
});

app.get('/messages', function (req, res) {
  var stream = fb.apiCall('GET', '/me/feed', {access_token: req.param('access_token'), message: req.param('message')});
  stream.pipe(fs.createWriteStream('backup_feed.txt'));
});

app.listen(3000);

Test

To test and see this module working:

make

License

(The MIT License)

Copyright (c) 2010-2011 Pau Ramon masylum@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.