Created
June 3, 2013 21:40
-
-
Save peregrinogris/5701673 to your computer and use it in GitHub Desktop.
Klout Score Grouper. Requires `request` nodejs module, and you have to edit the file to add your Klout API key and the twitter handles you want to query Klout for scores.
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
var request = require('request'); | |
var api_key = "<KLOUT_API_KEY>"; | |
var handles = ["user1", "user2"]; | |
var twitter_url = "http://api.klout.com/v2/identity.json/twitter?screenName="; | |
var klout_url = "http://api.klout.com/v2/user.json/:klout_id/score?"; | |
var user, sum = 0, idx = 0; | |
function addUpUser(){ | |
if (idx == handles.length) { | |
console.log("Grouped Klout Score:",sum); | |
} else { | |
user = handles[idx]; | |
request.get({ | |
url: twitter_url+user+"&key="+api_key, | |
json: true | |
}, function(e,r,data){ | |
request.get({ | |
url: klout_url.replace(':klout_id',data.id)+"&key="+api_key, | |
json: true | |
}, function(e,r,klout){ | |
console.log("Added @"+user,":",klout.score); | |
sum += klout.score; | |
idx++; | |
// This is not cool, but klout limits 10 calls per second, so let's be | |
// on the safe side... | |
setTimeout(addUpUser, 1000); | |
}); | |
}); | |
} | |
} | |
addUpUser(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment