Yesterday morning, @ambrouk tweeted: “Is there a tool where you can quickly check 2 twitter accs and find out who follows both? I.e who can see the exchanges between A and B?”
(Explanatory note: if you start a tweet with @name, only your twitter followers who also follow @name will see the tweet in their stream.)
There probably is, but I thought it’d be an interesting exercise to see if I could put a script together to do this in a web page without requiring authenticated access to the Twitter API using the Google Social Graph API.
If you go to the Social Graph API Parameter Playground, you can use the tool provided to construct API calling URLs that return the people you follow on Twitter, or who follow you, as well as various other bits of social data…
The data is returned as JSON, so it’s easy enough to pull into a web page. So here’s a view of my ‘common twitter friends’ single page web app:
And here’s the script that does it, pulling back the common friends or common followers of two folks on Twitter:
<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' Xers=new Array(); coXs=new Array(); for (u in json['nodes']) { name[name.length]=u.replace('http://twitter.com/','') lXers=new Array() for (i in json['nodes'][u][nref]) lXers[lXers.length]=i Xers[Xers.length]=lXers } $("#u1n").html(name[0]+': ') $("#u1nn").html(' with '+name[0]) $("#u1c").html(Xers[0].length+' '+typ) $("#u2n").html(name[1]+': ') $("#u2nn").html(' with '+name[1]) $("#u2c").html(Xers[1].length+' '+typ) for (i in Xers[0]){ if (Xers[1].indexOf(Xers[0][i])>-1){ coXs[coXs.length]=Xers[0][i] } } return coXs } </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>
With a bit of tweaking, it should be possible to generalise the code to find the common followers of N friends (please post a link to the script in a comment if you do this:-)
Rather than me hosting the script, you’ll have to run it yourself. Save the raw code from here as an .html file on your desktop, then drag it and drop it into a browser window (or more laboriously, open the file you saved from the browser file menu).
[UPDATE: try it out here – Common Twitter friends]
PS I’m not sure that the limits are on the Google Social Graph API, whether in terms of the number of accounts that can be included in a single query, the size of the returned payload from a single query, or the number of queries per minute/hour/day, so I’m not sure if this represents a way round the Twitter API limit if all you’re doing is calling on friends and followers lists?