8 # When Net::Twitter::Lite encounters a Twitter API error or a network error,
9 # it throws a Net::Twitter::Lite::Error object.
10 # You can catch and process these exceptions by using eval blocks and testing $@
11 ## from http://search.cpan.org/perldoc?Net::Twitter::Lite#ERROR_HANDLING
12 use Net::Twitter::Lite;
19 die "usage: $0 screen_name [number_of_pages|all [dump]]\n";
21 my $screen_name = $ARGV[0];
22 my $pages = $ARGV[1] || 1;
23 if ($pages eq 'all') {
26 my $dump = $ARGV[2] || 0;
28 my $conf = loadconf("$Bin/config.yml");
29 if (! defined $conf) {
30 die "$0: cannot parse config file.\n";
33 my $bot = login($conf);
34 if (! $bot->authorized) {
35 die "$0: this client is not yet authorized.\n";
41 while ($pages - $page && $page <= 160) {
43 my $res = $bot->user_timeline(
45 screen_name => $screen_name,
51 foreach my $line (split /\n/, Dumper $res) {
52 if ($line =~ /undef/) { next; }
57 foreach my $status (@{$res}) {
59 $text .= $status->{user}{name};
60 $text .= " [" . $status->{created_at} . "]";
61 $text .= " (". $status->{id} . ")";
62 $text .= " ". encode('utf8', $status->{text});
76 # load configration data from yaml formatted file
77 # param => scalar string of filename
78 # ret => hash object of yaml data
82 my $yaml = YAML::Tiny->read($file);
85 warn "$0: '$file' $!\n";
92 # make Net::Twitter::Lite object and login
93 # param => hash object of configration
94 # ret => Net::Twitter::Lite object
98 my $bot = Net::Twitter::Lite->new(
99 consumer_key => $conf->{consumer_key},
100 consumer_secret => $conf->{consumer_secret},
103 $bot->access_token($conf->{access_token});
104 $bot->access_token_secret($conf->{access_token_secret});
110 # output error message at eval error
112 use Scalar::Util qw(blessed);
114 if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) {
116 if ($@->twitter_error) {
117 my %twitter_error = %{$@->twitter_error};
119 $twitter_error{"$_ => "} = $twitter_error{$_} . "\n";
120 delete $twitter_error{$_}
121 } keys %twitter_error;
122 warn join("", %twitter_error);