Common Friends or Followers on Twitter

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…

Google Social API parameter playground

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:

Common twitter friends

And here’s the script that does it, pulling back the common friends or common followers of two folks on Twitter:


<script type="text/javascript" src=""></script> 
<script type="text/javascript">

function compareUsers(typ){
  if (typ=='followers'){
  } else {

  var content = "";
     if(json) {
       if (typ=='followers')
         content = commonFollowers(json);
         content = commonFriends(json);
     } else {
       content = "The request did not return results.";
     var list=''
     for (i in content)
       if (content[i].indexOf('')==-1)
     	list+=" "+content[i].replace('','')
     $("#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')
  Xers=new Array();
  coXs=new Array();

  for (u in json['nodes']) {
	lXers=new Array()
	for (i in json['nodes'][u][nref])
  $("#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){
  return coXs


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")' />
<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>
<div id="output"></div>


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?