Created
February 20, 2013 18:35
-
-
Save finnp/4997859 to your computer and use it in GitHub Desktop.
Little script in node.js which uses the facebook API to rank users within a group by number of recent posts. This has been done within HelsinkiJS #Peerprogramming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Give the script a facebook token and a group id | |
var APIKEY = ""; | |
var GROUP = ""; | |
var https = require('https'); | |
https.get({hostname:'graph.facebook.com', path:'/' + GROUP + '/feed?access_token=' + APIKEY, agent:false}, function (res) { | |
var chunks = []; | |
res.on('data', function (chunk) { | |
chunks.push(chunk.toString()); | |
}); | |
res.on('end', function() { | |
json = JSON.parse(chunks.join("")); | |
rankUsers(json); | |
}); | |
}); | |
var rankUsers = function(json) { | |
var postCount = {}; | |
json.data.forEach(function(post) { | |
if(postCount[post.from.name] ) { | |
postCount[post.from.name]++; | |
} else { | |
postCount[post.from.name] = 1; | |
} | |
}); | |
var postCountArr = [] | |
for(var key in postCount) { | |
postCountArr.push([key, postCount[key]]); | |
} | |
postCountArr.sort(function(a,b) {return a[1] < b[1];}); | |
for(var i = 0; i<postCountArr.length; i++) { | |
console.log((i+1) + "." + postCountArr[i][0]); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment