How to bulk Unfollow on Twitter using Perl

If you are an active Twitter user and are following huge number of users but would now like to reduce the list, here’s a handy Perl script that allows you to Unfollow users in Bulk.Usually you want to start with Unfollowing Twitter users who don’t follow you and this script allows you to do just that.

Pre-requisites:

  • Twitter API Key – You can get this by registering your App at https://dev.twitter.com/apps. You will need the following keys
    • Consumer key
    • Consumer secret
    • Access Token (oauth_token)
    • Access Token Secret (oauth_token_secret)
  • Perl (Windows or Linux/Unix)
  • Perl module Net::Twitter::Lite

Let’s get coding…


#!/usr/bin/perl -w

use strict;
use Net::Twitter::Lite;

my $nt=Net::Twitter::Lite->new(
 consumer_key        =>'Your Twitter consumer key',
 consumer_secret     =>'Consumer secret',
 access_token        =>'Access token',
 access_token_secret =>'Access token secret'
);

#-- Friends are the users you follow
#-- Followers are users who follow you
#-- A difference (Friends MINUS Followers) will give a list
#-- of users who don't Follow you
#-- This way of calculation saves on API Rate limiting
#-- issues because you can do most of the calculations within
#-- your own app rather than calling Twitter API to find if a
#-- particular user Follows you.

#-- Config begin -------------------------------------
my($cnt,$followers,@friends)=(0,"",());
my($id)=("XXXXXXXX"); #-- Your Twitter id
my($count)=(100); #- How many to Unfollow in one run
#-- Config end ---------------------------------------

#-- Fetch followers
eval{$followers=join(' ',@{$nt->followers_ids($id)});};
if($@){print "\n\n$@\n"; exit 1; }

#-- Fetch friends
eval{@friends=@{$nt->friends_ids($id)};};
if($@){print "\n\n$@\n";exit 2;}

#-- Now find which of the friends does not follow you
for my $friend (@friends){
 if(index($followers,$friend)>=0){
 print "\n$friend follows $id";
 }
 else{
 #-- At this point, Unfollow the Friend if you like
 eval{
 my $fname=$nt->destroy_friend($friend);
 $cnt+=1;
 print "\n$cnt. Unfollowing $fname->{screen_name}...";
 };
 print "\n$@" if $@;
 last if $cnt==$count;
 }
}

print "\n\n";

1;

Find contemporary furniture at competitive prices on http://www.blackfishliving.co.uk

If you like this post, please consider sharing...

Rating:
58.0
87 votes
1 2 3 4 5

Leave a Reply


About

IT Professional and enthusiast photographer. Connect with me on Google+