public
Last active

show common friends of two twitter users

  • Download Gist
commonfriends.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
<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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.