Skip to content

Instantly share code, notes, and snippets.

@jeduan
Last active December 13, 2015 17:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeduan/4950863 to your computer and use it in GitHub Desktop.
Save jeduan/4950863 to your computer and use it in GitHub Desktop.
Made these quick functions to get the number of twitter followers and klout score of a given twitter username on Google Spreadsheets

Made these quick functions to get the number of twitter followers and klout score of a given twitter username.

Supports both @username and username as input.

To use them you have to create a Google Drive Spreadsheet and then go to Tools -> Script Editor, and then paste one or both Then the functions will be available as normal functions and you can use them as =followers(CELL_OR_SCREENNAME) and =klout(CELL_OR_SCREENNAME)

function klout(screen_name) {
if (!screen_name) {
return 'input?';
}
if (screen_name.substr(0,1) == "@") {
screen_name = screen_name.substr(1);
}
var key = "ENTER YOUR KLOUT KEY HERE";
var url = "http://api.klout.com/v2/identity.json/twitter?screenName="+screen_name+"&key="+key
var res = UrlFetchApp.fetch(url).getContentText();
var obj = Utilities.jsonParse(res);
if (! obj["id"] ) {
return "NOT AVAILABLE";
}
var id = obj['id'];
url = "http://api.klout.com/v2/user.json/"+id+"/score?key="+key;
res = UrlFetchApp.fetch(url).getContentText();
obj = Utilities.jsonParse(res);
if (! obj["score"]) {
return "NOT AVAILABLE";
}
return obj["score"];
}
function followers(screen_name) {
if (!screen_name) {
return 'input?';
}
if (screen_name.substr(0,1) == "@") {
screen_name = screen_name.substr(1);
}
var url = "https://api.twitter.com/1/users/show.json?screen_name="+screen_name;
var res = UrlFetchApp.fetch(url).getContentText();
var obj = Utilities.jsonParse(res);
if (! obj["followers_count"] ) {
return "BAD USERNAME";
} else {
return obj["followers_count"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment