facebook-graph

0.0.6 • Public • Published

Facebook Node.js SDK

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.

This client library is designed to support the Facebook Graph API and the official Facebook JavaScript SDK, which is the canonical way to implement Facebook authentication. You can read more about the Graph API at http://developers.facebook.com/docs/api.

Installation

npm install facebook-graph

Development

git clone https://github.com/gasi/node-facebook-graph.git facebook-graph
npm link ./facebook-graph

Running Tests

node test

Basic usage

var facebook = require('facebook-graph');
var accessToken = '<Your OAuth Access Token>';
var graph = new facebook.GraphAPI(accessToken);

function print(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-graph');
var user = facebook.getUserFromCookie(req.cookies, appId, appSecret);
if (user) {
    var graph = new facebook.GraphAPI(user['access_token']);
    function print(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 and Facebook PHP SDK.

Thanks for supporting open source, Facebook.

Reporting Issues

Please file bugs or other issues in our issues tracker.

Readme

Keywords

none

Package Sidebar

Install

npm i facebook-graph

Weekly Downloads

7

Version

0.0.6

License

none

Last publish

Collaborators

  • gasi