Skip to content

Instantly share code, notes, and snippets.

@KarlHerler
Created May 23, 2011 14:01
Show Gist options
  • Save KarlHerler/986740 to your computer and use it in GitHub Desktop.
Save KarlHerler/986740 to your computer and use it in GitHub Desktop.
Gets attendees from a specific facebook event (based on a eventid) and returns their name
var request = require('request'),
jsdom = require('jsdom'),
sys = require('sys');
function getAttendees(eventID, accessToken, callback) {
var attendees;
console.log("fetching: "+"https://graph.facebook.com/"+eventID+"/attending?access_token="+accessToken);
request({uri:"https://graph.facebook.com/"+eventID+"/attending?access_token="+accessToken}, function (error, response, body) {
console.log("sucess!");
if (!error && response.statusCode == 200) {
data = JSON.parse(body);
if (data.data[0]) {
attendees = data.data[0].name;
for (i=1; i<data.data.length; i++) {
attendees = attendees+", "+data.data[i].name;
}
} else {
attendees = "Error, could not get a event by that ID or the token has expired";
}
}
callback(attendees);
});
}
var http = require('http');
var s = http.createServer(function (req, res) {
var url = req.url.split("/")[1];
var accessToken = "2227470867|2.PBaTz9xoa6_JJDOsYQ1YYA__.3600.1303059600.0-1008281448|tPnjoXL2p2TGvZ6iNoBgWT4pwm8";
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write("Fetching attendees for: "+url+"\n");
if(url!="favicon.ico") {
getAttendees(url, accessToken, function(data) {
res.end(data);
});
}
});
s.listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment