Skip to content

weizhu/nodejs-facebook-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published