Get twitter user information and details with perl


If you are wondering how to pull information of a certain user from twitter, wondering what he is saying and the number of people following him.
These can be done with the following code. This code runs even under proxy. So you don't have to worry if some filthy animals have set proxy upon your freedom to use internet.

Here I have used  the twitter::badge, html::linkextor, lwp::useragent modules of perl to do all the coding. You don't have to authenticate yourself before accessing the information.

When i designed the code, i first run into a problem. I could not derive the user id of the specific user.
I had to query his site and then find his id from the site. So if anyone, you know how to pull the user id from any sort of module or so, please write down.

The code is in perl programming language:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
——————— In twitter follow me @tneupaney —————————————–
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

use Twitter::Badge;
use HTML::LinkExtor;
require LWP::UserAgent;
 
my $user = shift;

my $extor = HTML::LinkExtor->new(undef, $URL);
my $ua = LWP::UserAgent->new;

$ua->timeout(10);
$ua->env_proxy;

my $response = $ua->get("http://twitter.com/$user");

if ($response->is_success) {
        $result = $response->decoded_content;

    $extor->parse($result)->eof;
    my @rs = $extor->links;
    foreach $lnk (@rs)
    {
        if ($$lnk[2] =~ m/.rss$/) {
            @rmslash = split(/\//, $$lnk[2]);
            @lnk_rss = split(/\./, @rmslash[5]);
            $i =@lnk_rss[0];
            $j = badge($i);
            exit;
        }
    }
}
else {
    die $response->status_line;
}

sub
badge
{
        my $id = shift;                          
        my $twitter = Twitter::Badge->new(id => $id);
        $twitter->fetch();                          

        print $twitter->name.' says – '.$twitter->text."\n";
        print $twitter->name.' has '.$twitter->followers_count." followers\n";
}

Posted via email from Linux fanatic