Skip to content

Instantly share code, notes, and snippets.

@serdary
Created March 27, 2014 23:47
Show Gist options
  • Save serdary/9821773 to your computer and use it in GitHub Desktop.
Save serdary/9821773 to your computer and use it in GitHub Desktop.
node code to verify & listen facebook real time subscription events
var qs = require('querystring');
var verifyToken = 'tekken';
var processRequest = function(req, callback) {
var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
callback(qs.parse(body));
});
}
var http = require('http');
http.createServer(function (req, res) {
console.log("got a request")
processRequest(req, function(data) {
console.log("data:" + JSON.stringify(data));
console.log("req method is:" + req.method);
if (req.method === 'GET') {
var queryString = req.url.split('?')[1];
var params = qs.parse(queryString);
console.log(params);
if (params["hub.mode"] === 'subscribe' && params["hub.verify_token"] === verifyToken) {
res.end(params["hub.challenge"]);
} else {
res.end("invalid GET request")
}
} else {
res.end(JSON.stringify(data));
}
});
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment