Twitter::Badge - Perl module that displays the current Twitter information of a user
use Twitter::Badge; # If you know the Twitter ID my $id = 14512139; # define the Twitter ID my $twitter = Twitter::Badge->new(id => $id); # create the object for that ID $twitter->fetch(); # get information for this ID # Display status print $twitter->name.' says - '.$twitter->text."\n"; # display status print $twitter->name.' has '.$twitter->followers_count." followers\n"; # display followers # .. and so on
Twitter::Badge is a class that retrieves the Twitter information for the user's ID or screen name.
The method new(%args) creates and returns a new Twitter::Badge object. It takes either zero parameters or a hash containing at least one of the following:
new(%args)
Twitter::Badge
KEY DEFAULT VALUE =========== ============= id undef screen_name undef ua Mozilla/4.0
id
[OPTIONAL] This parameter is the Twitter ID, a number that is associated with the Twitter screen name.
screen_name
[OPTIONAL] This parameter is the Twitter screen name.
ua
[OPTIONAL] This parameter is the User-Agent string that is included in the request to Twitter. You can find a list of user-agent strings at http://aruljohn.com/ua/
The method fetch() fetches the following information from the user's corresponding Twitter account:
fetch()
name
text
profile_image_url
followers_count
created_at
The method screen_name() returns the screen_name value. If a parameter is passed into it, screen_name is set to that value.
screen_name()
This print the current Twitter screen name. print $twitter->screen_name
This will set the current Twitter screen name to 'aruljohn'. $twitter->screen_name('aruljohn');
The method ua() returns the User-Agent string value. If a parameter is passed into it, ua is set to that value. You can find a list of User-Agent strings at http://aruljohn.com/ua/
ua()
The method name() returns the name value retrieved from the account specified by the Twitter ID.
name()
The method text() returns the text value retrieved from the account specified by the Twitter ID.
text()
The method profile_image_url() returns the profile_image_url value retrieved from the account specified by the Twitter ID
profile_image_url()
The method followers_count() returns the followers_count value retrieved from the account specified by the Twitter ID.
followers_count()
The method created_at() returns the created_at value - the time the user updated his/her Twitter status.
created_at()
use Twitter::Badge; my $twitter = Twitter::Badge->new(); # create an empty Twitter::Badge object # Setting Twitter ID $twitter->id(14512139); # setting ID to 14512139 $twitter->fetch(); # fetch Twitter info [with that Twitter ID] print $twitter->name.' says: '.$twitter->text."\n"; print $twitter->name.' posted on '.$twitter->created_at."\n";
use Twitter::Badge; # Create object with screen name $twitter = Twitter::Badge->new(screen_name => 'justjul'); # create the object $twitter->fetch(); print $twitter->name.' says: '.$twitter->text."\n"; print $twitter->name.' posted on '.$twitter->created_at."\n";
use Twitter::Badge; # Create object with User-Agent $twitter = Twitter::Badge->new(ua => 'Mozilla/6.0 (Twitterbot)'); # create the object $twitter->screen_name('aruljohn'); $twitter->fetch(); print $twitter->name.' says: '.$twitter->text."\n"; print $twitter->name.' posted on '.$twitter->created_at."\n\n"; # Change screen name $twitter->screen_name('justjul'); $twitter->fetch(); print $twitter->name.' says: '.$twitter->text."\n" if defined $twitter->text; print $twitter->name.' posted on '.$twitter->created_at."\n" if defined $twitter->created_at; print $twitter->name.' has '.$twitter->followers_count." followers\n\n" if defined $twitter->followers_count;
You can use the Data::Dumper module to check the contents of $twitter at any time.
$twitter
use Data::Dumper; # other code goes here print Dumper($twitter);
There are no known bugs as of now.
But since the Twitter::Badge module is built on the XML file that Twitter generates - and this is bound to change over a period of time - some methods may stop working. When that happens, I will update this module. I will also update the module if Twitter includes more useful content in its XML file, and on user requests. My email address for contact is <arul@cpan.org>
Twitter API Documentation - http://groups.google.com/group/twitter-development-talk/web/api-documentation
Arul John - http://aruljohn.com
Copyright (C) 2008 by Arul John
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or, at your option, any later version of Perl you may have available.
To install Twitter::Badge, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Twitter::Badge
CPAN shell
perl -MCPAN -e shell install Twitter::Badge
For more information on module installation, please visit the detailed CPAN module installation guide.