How to auto-follow on Twitter

BBEdit

Image via Wikipedia

UPDATE:

As of September 1, 2010, Twitter has nuked functions like this from orbit. I now recommend you download and install the free TTYtter software from Floodgap Software that does substantially the same thing but is compliant with Twitter’s OAuth protocols.

The old post is kept below only for historical purposes.

Ever since announcing that I’d basically follow anyone who’s followed me, I had to come up with a way to make this happen in a timely, efficient process. So here’s how I do it, if you want to use this bizarre workflow yourself.

  1. Aggregate all the “now following you” emails from Twitter in Mozilla Thunderbird.
  2. In Thunderbird, filter all these to a separate folder.
  3. On disk, open the Twitter folder in BBEdit.
  4. Extract all the lines containing “is now following”.
  5. De-dupe, then dump these into a text file.
  6. Strip out the Twitter usernames in parentheses.
  7. Copy and paste that list into a plain text file I call follow.txt.
  8. Run fu.php (a php script) to process those user names.
  9. Done!

fu.php is more or less the magic sauce along with BBEdit. I do this once every day or so to sync up new followers, and it works like a charm. fu.php I run in the Mac OS Terminal. This process looks complex, but in reality, it takes all of 2 minutes to do at most.

Here’s the source code:

<?php
// curl twitter follow script

set_time_limit(3600);

function follow($username)
{
$url = “http://username:[email protected]/friendships/create/$username.json”;

if (!$curld = curl_init()) {
echo “Could not initialize cURL session.n”;
exit;
}

echo $url;
if (!$curld = curl_init()) {
echo “Could not initialize cURL session.n”;
exit;
}

curl_setopt($curld, CURLOPT_GET, true);
curl_setopt($curld, CURLOPT_URL, $url);
curl_setopt($curld, CURLOPT_HEADER, false);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output=curl_exec($curld);

//echo “Received data: nn$outputnn”;

$pile=json_decode($output,true);
return $pile;

}

$handle = @fopen(“follow.txt”, “r”);
if ($handle) {
while (!feof($handle)) {
$users[] = fgets($handle, 4096);
}
fclose($handle);
}

foreach($users as $key=> $value){
$user=ereg_replace(“n”,”",$value);
$result=follow($user);
print_r($result);
}

?>

Did you enjoy this blog post? If so, please subscribe right now!

Get this and other great articles from the source at www.ChristopherSPenn.com

Zemanta Pixie

Related posts:

  1. My Twitter Follow Policy
  2. Why Twitter Matters : It's Your AP Newswire
  3. Re-syncing Twitter
  • Anonymous

    Seems like a lot of work when you can just use Twitter Karma. http://dossy.org/twitter/karma/

  • http://pikpr.blogspot.com annie heckenberger

    Seems like a lot of work when you can just use Twitter Karma. http://dossy.org/twitter/karma/

  • http://danieljohnsonjr.blogspot.com/2008/05/my-virtual-business-card.html Daniel Johnson, Jr.

    This is interesting. I wonder how much of an API hit this takes. I bet you probably run this at night when you’re not going to be using Twitter that much anyway.

    I don’t know enough about PHP and BBEdit yet to be able to implement this on Windows.

  • http://danieljohnsonjr.blogspot.com/2008/05/my-virtual-business-card.html Daniel Johnson, Jr.

    This is interesting. I wonder how much of an API hit this takes. I bet you probably run this at night when you’re not going to be using Twitter that much anyway.

    I don’t know enough about PHP and BBEdit yet to be able to implement this on Windows.

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Twitter Karma blows up on me – too many followers.

    Dan – it definitely takes an API hit. I’m working on a version that does NOT hit the API.

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Twitter Karma blows up on me – too many followers.

    Dan – it definitely takes an API hit. I’m working on a version that does NOT hit the API.

  • http://www.FordRangerForum.com Ford Ranger Forum

    i agree with you on this completely.visited your blog first time today.but will surely come again.

  • Anthony

    Chris — have you sorted out a version that doesn't hit the API? Not sure how you could do that. Would love to hear how you are doing this.

  • Anthony

    Chris — have you sorted out a version that doesn't hit the API? Not sure how you could do that. Would love to hear how you are doing this.

  • Anthony

    Chris — have you sorted out a version that doesn't hit the API? Not sure how you could do that. Would love to hear how you are doing this.

  • Anthony

    Chris — have you sorted out a version that doesn't hit the API? Not sure how you could do that. Would love to hear how you are doing this.

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Haven't been able to do it without the API yet…

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Haven't been able to do it without the API yet…

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Haven't been able to do it without the API yet…

  • http://www.ChristopherSPenn.com Christopher S. Penn

    Haven't been able to do it without the API yet…

  • Pingback: Twitter Auto Follow Tools and Scripts

  • Pingback: 8 Tools, Scripts, or Apps to Follow and Unfollow on Twitter. | There's a Blog in my Soup!

  • http://twitter.com/ForeverOneTeam Bogdan

    do you have a youtube video with the steps to do this?

  • http://twitter.com/ForeverOneTeam Bogdan

    do you have a youtube video with the steps to do this?

  • http://twitter.com/ForeverOneTeam Bogdan

    do you have a youtube video with the steps to do this?

  • http://twitter.com/ForeverOneTeam Bogdan

    do you have a youtube video with the steps to do this?

  • aalaap

    A better way of doing this would be to make the follow script check POP3 email, find any “.. is following you” emails and follow them. Put it in a cron at regular intervals (say, every 5 minutes) and you're done.

    The friendships/create method is not subject to API rate limits, but there is a limit on the number of people you can follow in a day or hour or something. I think its 2000 per day at the moment.

  • aalaap

    A better way of doing this would be to make the follow script check POP3 email, find any “.. is following you” emails and follow them. Put it in a cron at regular intervals (say, every 5 minutes) and you're done.

    The friendships/create method is not subject to API rate limits, but there is a limit on the number of people you can follow in a day or hour or something. I think its 2000 per day at the moment.

  • http://www.aming.info/ Aming

    yea, that's I've been looking for! You know it was make me mad when I should using twitter and I should follow back anyone who follow me! You know it was waste the time. Thank for your information

  • http://www.aming.info/ Aming

    yea, that's I've been looking for! You know it was make me mad when I should using twitter and I should follow back anyone who follow me! You know it was waste the time. Thank for your information

  • netsparx

    If you have a domain for email you can pipe the email to a php file to strip the line with the user name and presto call it from there on.

    In cpanel hosting there is an option to filter emails which can be “piped” to a file.

    Let the php do it's magic instantly. Hmmm…

  • netsparx

    If you have a domain for email you can pipe the email to a php file to strip the line with the user name and presto call it from there on.

    In cpanel hosting there is an option to filter emails which can be “piped” to a file.

    Let the php do it's magic instantly. Hmmm…

  • frederico

    THX, this is very good and so much easier…. have a good day

  • frederico

    THX, this is very good and so much easier…. have a good day

  • frederico

    THX, this is very good and so much easier…. have a good day

  • Pingback: Vox Populi: Q1 2010 | Christopher S. Penn's Awaken Your Superhero

  • J@mes

    The code doesnt work, tried to run it using php and i got an error message anyone knows how to fix the problem or another working script that functions

  • J@mes

    This code has refused to run when i compiled it using easyphp, anyone knows how to correct this or any other script that functions??

    • http://www.ChristopherSPenn.com Christopher S. Penn

      This has long since expired, sir. I now recommend you get and install TTYtter which supports the same functionality.

      • Pathi M Graf

        Hi Christoper, i just started to use TTYtter, but i did found a solution, how to auto-follow. Could you push me to right direction?