rahulg
rahulg

Reputation: 2249

How to integrate Facebook SDK into node js?

One benefit of node js that we can use the ready made huge base of javascript libraries? So, I was wondering how to integrate the Facebook sdk at http://connect.facebook.net/en_US/sdk.js into my node project?

I am a bit new to Node so the question might be naive..

Upvotes: 2

Views: 6055

Answers (2)

Node
Node

Reputation: 86

Try this .

First do npm install facebook-nodejs-sdk
And then 
var connect = require('connect'),
fbsdk = require('facebook-sdk');

connect()
.use(connect.cookieParser())
.use(connect.bodyParser())
.use(fbsdk.facebook({
appId  : 'YOUR APP ID',
secret : 'YOUR API SECRET'
}))
.use(function(req, res, next) {

if (req.facebook.getSession()) {
  res.end('<a href="' + req.facebook.getLogoutUrl() + '">Logout</a>');

  // get my graph api information
  req.facebook.api('/profile', function(me) {
      console.log(me);
  });

} else {
    res.end('<a href="' + req.facebook.getLoginUrl() + '">Login</a>');
}

 })
   .listen(9000);

Upvotes: 0

Tobi
Tobi

Reputation: 31479

You cannot integrate the Facebook SDK directly. There are some libraries at http://npmjs.org which deal with Facebook connectivity, but most of them are quite old.

If you're just looking for Facebook Login integration, https://www.npmjs.org/package/passport-facebook could be a starting point.

I ended up developing my of "library", which is not too complicated because the Facebook Graph API can be used via standard HTTP requests.

Upvotes: 3

Related Questions