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 https://dev.twitter.com/apps). You will also need the Perl interface to the Twitter API – Net::Twitter.

#!/usr/bin/perl 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: $_

"; my $r2 = $twitter->destroy_friend({ user_id => $_ }); } }

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