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

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Readme.md

facebook-js

Easy peasy facebook client for connect.

npm install facebook-js

Usage

facebook-js has three methods.

  • getAuthorizeUrl(client_id, redirect_uri, options) Gets the url to facebook.
  • getAccesToken(params, callback): Uses oAuth module to retrieve the access_token
  • apiCall(http_method, path, params, callback): Does a call to facebook graph API.

Example using express.js

var express = require('express'),
    connect = require('connect'),
    facebookClient = require('./../')(
      'appID',
      'appSecret'
    ),
    app = express.createServer(
      connect.bodyDecoder(),
      connect.cookieDecoder(),
      connect.session()
    );

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

app.get('/auth', function (req, res) {
  facebookClient.getAccessToken({redirect_uri: 'http://localhost:3003/auth', code: req.param('code')}, function (error, token) {
    res.render('client.jade', {locals: {token: token}});
  });
});

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

app.listen(3003);

Test

To test and see this module working:

  • clone this repo and open the test folder
  • create a facebook app with the url pointing to http://localhost:3003/
  • set up the keys and password of your facebook app at client.js file
  • run it! node test/client.js
  • Open your browser at localhost:3003
Something went wrong with that request. Please try again.