Twitter Mass Unfollower in Perl

Sometimes automated tests can cause you to add many unwanted twitter accounts – (yes I’m looking at you spam and porn); Also, twitter has a follow limit based on a whole plethora of metrics. This can lead to one wanting to ‘unfollow’ everyone, and start afresh…

We can easily solve this with several lines of Perl, and a Twitter API key (grab one by registering your App at You will also need the Perl interface to the Twitter API – Net::Twitter.

use strict;
use warnings;
use Net::Twitter;

# Auth tokens
my %tokens = (
        consumer_key    => 'YOUR_CONSUMER_KEY',
        consumer_secret => 'YOUR_CONSUMER_SECRET',
        access_token => 'YOUR_ACCESS_TOKEN',
        access_token_secret => 'YOUR_ACCESS_TOKEN_SECRET',

#create our twitter instance
my $twitter = Net::Twitter->new(traits => [qw/API::RESTv1_1/], %tokens, ssl=>1);

#loop through the 'cursors' to grab all the results of our friends_ids
for ( my $cursor = -1, my $r; $cursor; $cursor = $r->{next_cursor} ) {
        # result is list of friends
        $r = $twitter->friends_ids({ cursor => $cursor });
        # loop through all the id's and delete them
        foreach (@{$r->{ids}}){
                print "Deleting User: $_\n";
                my $r2 = $twitter->destroy_friend({ user_id => $_ });

After running the script, your account should now be following no-one. Enjoy the blank slate!


One thought on “Twitter Mass Unfollower in Perl

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s