Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 samples
Octocat-spinner-32 README.md
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
README.md

facebook-sdk SDK for Facebook integration

Install

TODO

Basic Use

Initialization

var config = {
  ns:     '<Facebook App Namespace',
  id:     '<app id>',
  secret: '<app secret>',
  scope:  '<additional required permissions>',
};

var fbsdk = require('facebook_sdk').init(config);

Use in Express

Add a single line in yoour Express config code.

app.use(fbsdk.auth);

After that, the req object in request handler will have object 'facebook' that you can use to make API calls, get login status and current user id, etc.

app.all('/', function(req, res) {
  var facebook = req.facebook;
  if (facebook && facebook.signedRequest.user_id) {
    facebook.api('me', function(er, me) {
      // Now 'me' contains info (name, id, work, gender, etc.) for current user
      res.render('index', {config: config, me: me});
    });
  } else {
    res.redirect(fbsdk.loginURL(fbsdk.canvasURL));
  }
});

Make Graph API calls with App Access Token

You can also make API calls with app access token at anytime easily.

fbsdk.appApi(config.id + '?fields=id,name,canvas_url', function(e, result) {
  console.log("Got app info using app access token", result);
});

or

fbsdk.appApi(config.id, 
  {
    fields: 'id,name,canvas_url',
  },  function(e, result) {
  console.log("Got app info using app access token", result);
});

Something went wrong with that request. Please try again.