A small backbone.js helper to make login with Facebook API.
- Backbone
- Download the library
- Require the library (CommonJS, AMD and Browser ready)
- Pass in credentials your Facebook App ID
- You're ready!
var FBLogin = require('backbone-facebook-login') // Can be AMD or Browser-in too
var fbLogin = new FBLogin({
credentials: {
appId: 'xxxx' // Your Facebook App Id
}
});
fbLogin.init(); // Initialize the SDK
fbLogin.login(); // Make user login request
With scope
fbLogin.login({
scope: 'public_profile, email, user_education_history'
}));
So, you can access login status
fbLogin.get('loginStatus');
With your SDK initialized (step above)
fbLogin.getUserData('/me', 'user'); // User is the name that will appear in the object
fbLogin.getUserData('/me/picture', 'image', {width: 320; height: 320}); // A third parameter can be passed (Graph API options)
So, you can access data (If the request have a error, nothing will be stored)
fbLogin.get('user');
fbLogin.get('picture');
fbLogin.logout();
Enjoy :)