Find Out Who You're Following But Isn't Following You On Twitter
Anyone who uses the Twitter website for their tweeting knows of the many limitations. One such limitation is the follower management. It is easy to get the basics — who you are following and who is following you. But it is very difficult to find out which of the people you are following are also following you. And until recently it was equally as difficult to see if you're following the people who are following you. Now the usefulness of those features assumes that you are the type of person who follows the people that follow you, and expect the same, which has long since been the custom on Twitter. As for me, I am that type of person, as long as it isn't obvious that the person following me is actually a Twitter spam bot. Although even the non-spam bots tend to be spammy on Twitter (don't worry, I have a solution for this in an upcoming article).
I understand that the power of Twitter lies in the Twitter API which has allowed the creation of several new Twitter clients, some of which have probably already have solved the above limitation. For those of us using the Twitter website or a client which has the above limitation, I present a simple script written in PHP that will generate a follower report:
<?php
require "TwitterQuery.class.php";
function twitter_friends ($username, $password)
{
$twitterQuery = new TwitterQuery();
$twitterQuery->setBasicAuth($username, $password);
$following = array();
for ($i = 1; ; $i++)
{
$query = $twitterQuery->query("statuses/friends", array("page" => $i));
if (count($query) == 0) break;
foreach ($query as $current)
{
$following[] = $current["screen_name"];
}
}
$followers = array();
for ($i = 1; ; $i++)
{
$query = $twitterQuery->query("statuses/followers", array("page" => $i));
if (count($query) == 0) break;
foreach ($query as $current)
{
$followers[] = $current["screen_name"];
}
}
$friends = array_intersect($following, $followers);
$following = array_diff($following, $friends);
$followers = array_diff($followers, $friends);
return array("friends" => $friends, "following" => $following, "followers" => $followers);
}
$friends = twitter_friends(username, password);
echo "Friends (People I am following and are following me):\n".implode(", ", $friends["friends"])."\n";
echo "People I am following but aren't following me:\n".implode(", ", $friends["following"])."\n";
echo "People following me that I am not following:\n".implode(", ", $friends["followers"])."\n";
?>
Download Source: twitter_friends.php
Note: this script uses TwitterQuery, my lightweight Twitter API which I introduced in a previous article.
Running that script, I get the following:
Friends (People I am following and are following me): JulianSpillane, Taire, gkelly, julielworkman, ... People I am following but aren't following me: spolsky, FroNoPro, BarackObama, ... People following me that I am not following: ...
Download Source: twitter_friends_result.txt
As someone who has seen his follower count go down, I know the convenience of being able to see who I am following but isn't following me. Using this script I can now easily pinpoint the person who no longer follows me.
On a side note, I think that the Twitter site should also have a kick ass plugin system to go along with their kick ass API, so that developers could simply create plugins for features like this, instead of creating an entirely new client.



