Created
December 12, 2010 19:56
-
-
Save psychemedia/738280 to your computer and use it in GitHub Desktop.
show common friends of two twitter users
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
<html><head><title></title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script> | |
<script type="text/javascript"> | |
function compareUsers(typ){ | |
if (typ=='followers'){ | |
gtyp='edi' | |
} else { | |
gtyp='edo' | |
} | |
url='http://socialgraph.apis.google.com/lookup?q=http://twitter.com/'+$('#user1').val()+',http://twitter.com/'+$('#user2').val()+'&'+gtyp+'=1&callback=?'; | |
var content = ""; | |
$.getJSON(url, | |
function(json){ | |
if(json) { | |
if (typ=='followers') | |
content = commonFollowers(json); | |
else | |
content = commonFriends(json); | |
} else { | |
content = "The request did not return results."; | |
} | |
var list='' | |
for (i in content) | |
if (content[i].indexOf('http://twitter.com/account/redirect_by_id')==-1) | |
list+=" "+content[i].replace('http://twitter.com/','') | |
$("#output").html(list); | |
$("#u1p").html('of which '+content.length+' in common') | |
$("#u2p").html('of which '+content.length+' in common') | |
} | |
); | |
} | |
function commonFriends(json){ | |
return commonXs(json,'friends') | |
} | |
function commonFollowers(json){ | |
return commonXs(json,'followers') | |
} | |
function commonXs(json,typ){ | |
var name=new Array() | |
if (typ=='followers') | |
nref='nodes_referenced_by' | |
else | |
nref='nodes_referenced' | |
followers=new Array(); | |
cofriends=new Array(); | |
for (u in json['nodes']) { | |
name[name.length]=u.replace('http://twitter.com/','') | |
lfollowers=new Array() | |
for (i in json['nodes'][u][nref]) | |
lfollowers[lfollowers.length]=i | |
followers[followers.length]=lfollowers | |
} | |
$("#u1n").html(name[0]+': ') | |
$("#u1nn").html(' with '+name[0]) | |
$("#u1c").html(followers[0].length+' '+typ) | |
$("#u2n").html(name[1]+': ') | |
$("#u2nn").html(' with '+name[1]) | |
$("#u2c").html(followers[1].length+' '+typ) | |
for (i in followers[0]){ | |
if (followers[1].indexOf(followers[0][i])>-1){ | |
cofriends[cofriends.length]=followers[0][i] | |
} | |
} | |
return cofriends | |
} | |
</script> | |
</head> | |
<body> | |
<form> | |
User 1: @<input type='text' id='user1' value="ambrouk" /> | |
User 2: @<input type='text' id='user2' value='psychemedia' /> | |
<input type='button' value='Find Common Followers' onclick='compareUsers("followers")' /> <input type='button' value='Find Common Friends' onclick='compareUsers("friends")' /> | |
</form> | |
<div><span id='u1n'></span> <span id='u1c'></span> <span id='u1p'></span> <span id='u2nn'></div> | |
<div><span id='u2n'></span> <span id='u2c'></span> <span id='u2p'></span> <span id='u1nn'></div> | |
<hr/> | |
<div id="output"></div> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment