This is a port of the official Facebook Python SDK to Node.js.
Why did I choose the Python SDK? Because it's simple, clean and beautiful code.
Besides, I only needed support for the Graph API.
git clone https://github.com/gasi/node-facebook-graph.git facebook-graphnpm link ./facebook-graph
Basic usage
var facebook = require('facebook');var accessToken = '<Your OAuth Access Token>';var graph = new facebook.GraphAPI(accessToken);var print = function (error, data) { console.log(error ? error : data);};graph.getObject('me', print);graph.getConnections('me', 'friends', print);graph.putObject('me', 'feed', {message: 'The computerz iz writing on my wallz!1'}, print);
Express JS
If you are using the module within a web application with the
JavaScript SDK, you can also use the module to use Facebook for
login, parsing the cookie set by the JavaScript SDK for logged in users.
For example, in in the Express web framework, you could get the
profile of the logged in user with:
// This snippet assumes that you're using the// connect.cookieParser (http://senchalabs.github.com/connect/middleware-cookieParser.html)// middleware.var facebook = require('facebook');var user = facebook.getUserFromCookie(req.cookies, appId, appSecret);if (user) { var graph = new facebook.GraphAPI(user['access_token']); var print = function (error, data) { console.log(error ? error : data); }; graph.getObject('me', print); graph.getConnections('me', 'friends', print); graph.putObject('me', 'feed', {message: 'The computerz iz writing on my wallz!1'}, print);}
Acknowledgements
Implementation and documentation ported from the official
Facebook Python SDK.
Thanks for supporting open source, Facebook.