Easy peasy facebook client for connect.
npm install facebook-js
facebook-js has three methods.
- getAuthorizeUrl(client_id, redirect_uri, options) Gets the url to facebook.
- getAccesToken(params, callback): Uses oAuth module to retrieve the access_token
- apiCall(http_method, path, params, callback): Does a call to facebook graph API.
var express = require('express'),
connect = require('connect'),
facebookClient = require('./../')(
'appID',
'appSecret'
),
app = express.createServer(
connect.bodyDecoder(),
connect.cookieDecoder(),
connect.session()
);
app.get('/', function (req, res) {
res.redirect(facebookClient.getAuthorizeUrl({
client_id: 'appID',
redirect_uri: 'http://localhost:3003/auth',
scope: 'offline_access,publish_stream'
}));
});
app.get('/auth', function (req, res) {
facebookClient.getAccessToken({redirect_uri: 'http://localhost:3003/auth', code: req.param('code')}, function (error, token) {
res.render('client.jade', {locals: {token: token}});
});
});
app.post('/message', function (req, res) {
facebookClient.apiCall('POST', '/me/feed',
{access_token: req.param('access_token'), message: req.param('message')},
function (error, result) {
res.render('done.jade');
}
);
});
app.listen(3003);
To test and see this module working:
- clone this repo and open the test folder
- create a facebook app with the url pointing to http://localhost:3003/
- set up the keys and password of your facebook app at client.js file
- run it! node test/client.js
- Open your browser at localhost:3003