Skip to content

Instantly share code, notes, and snippets.

@ktnyt
Created October 20, 2014 06:31
Show Gist options
  • Select an option

  • Save ktnyt/cbb27f99691092964843 to your computer and use it in GitHub Desktop.

Select an option

Save ktnyt/cbb27f99691092964843 to your computer and use it in GitHub Desktop.
Gets user status for given user
use strict;
use warnings;
use utf8;
use Encode;
use Scalar::Util 'blessed';
use Net::Twitter;
my $username = shift;
my $consumer_key = "";
my $consumer_secret = "";
my $access_token = "";
my $access_secret = "";
my $nt = Net::Twitter->new(
ssl => 1,
traits => [qw/API::RESTv1_1/],
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
access_token => $access_token,
access_token_secret => $access_secret
);
my @statuses;
eval{
my $max_id = undef;
my $tmp;
for(1..5) {
if($max_id) {
$tmp = $nt->user_timeline({screen_name => $username, count => 200, max_id => $max_id});
} else {
$tmp = $nt->user_timeline({screen_name => $username, count => 200});
}
for my $status (@$tmp) {
my $text = $status->{text};
printf STDERR "%s <%s> %s\n", $status->{created_at}, $status->{user}{screen_name}, encode_utf8($status->{text});
$max_id = $status->{id};
push @statuses, $status;
}
}
};
if(my $err = $@) {
die $@ unless blessed $err && $err->isa('Net::Twitter::Error');
warn "HTTP Response Code: ", $err->code, "\n",
"HTTP Messasge.....: ", $err->message, "\n",
"Twitter error.....: ", $err->error, "\n";
}
### Do something with @statuses...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment