Last change
on this file since 682d2d9 was
e960958,
checked in by Ken-ichi Mito <mitty@…>, 11 years ago
|
use Net::Twitter::Lite::WithAPIv1_1 instead of Net::Twitter::Lite
- s/Net::Twitter::Lite/Net::Twitter::Lite::WithAPIv1_1/g;
|
-
Property mode set to
100755
|
File size:
2.0 KB
|
Rev | Line | |
---|
[4e0b0a1] | 1 | #! /usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use utf8; |
---|
| 6 | |
---|
| 7 | ## IMPORTANT ## |
---|
| 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 |
---|
[e960958] | 12 | use Net::Twitter::Lite::WithAPIv1_1; |
---|
[6da7e2a] | 13 | use Data::Dumper; |
---|
[4e0b0a1] | 14 | |
---|
[e960958] | 15 | my $bot = Net::Twitter::Lite::WithAPIv1_1->new( |
---|
[43d739e] | 16 | legacy_lists_api => 0, |
---|
| 17 | ); |
---|
[4e0b0a1] | 18 | |
---|
[679d34a] | 19 | my $dump; |
---|
| 20 | if (defined $ARGV[0] and $ARGV[0] eq "-d") { |
---|
| 21 | $dump = shift @ARGV; |
---|
| 22 | } |
---|
| 23 | |
---|
[4e0b0a1] | 24 | eval { |
---|
| 25 | foreach my $id (@ARGV) { |
---|
[679d34a] | 26 | $id =~ /\/?(\d+)$/; |
---|
| 27 | $id = $1; |
---|
[4e0b0a1] | 28 | my $res = $bot->show_status($id); |
---|
[035465b] | 29 | foreach my $line (split /\n/, Dumper $res) { |
---|
| 30 | if ($line =~ /undef/) { next; } |
---|
[679d34a] | 31 | if (! $dump) { |
---|
| 32 | unless ($line =~ / => {/ |
---|
| 33 | || $line =~ / = / |
---|
| 34 | || $line =~ /status/ |
---|
| 35 | || $line =~ /'text'/ |
---|
| 36 | || $line =~ /created/ |
---|
| 37 | || $line =~ /'id'/ |
---|
| 38 | || $line =~ /name/ |
---|
| 39 | || $line =~ / },/ |
---|
| 40 | || $line =~ / };/ |
---|
| 41 | ) { next; } |
---|
| 42 | } |
---|
[035465b] | 43 | print $line, "\n"; |
---|
| 44 | } |
---|
[4e0b0a1] | 45 | } |
---|
| 46 | }; |
---|
| 47 | if ($@) { |
---|
| 48 | evalrescue($@); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | sub evalrescue { |
---|
| 53 | # output error message at eval error |
---|
| 54 | |
---|
| 55 | use Scalar::Util qw(blessed); |
---|
| 56 | |
---|
| 57 | if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) { |
---|
| 58 | warn $@->error; |
---|
| 59 | if ($@->twitter_error) { |
---|
[a5b6bf1] | 60 | my $twitter_error = $@->twitter_error; |
---|
| 61 | if (defined $twitter_error->{errors}) { |
---|
| 62 | foreach my $error (@{$twitter_error->{errors}}) { |
---|
| 63 | warn "code => " , $error->{code}, "\n"; |
---|
| 64 | warn "message => ", $error->{message}, "\n"; |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | else { |
---|
| 68 | # unknown HASH structure |
---|
| 69 | use Data::Dumper; |
---|
| 70 | warn Dumper $twitter_error; |
---|
| 71 | } |
---|
[4e0b0a1] | 72 | } |
---|
| 73 | } |
---|
| 74 | else { |
---|
| 75 | warn $@; |
---|
| 76 | } |
---|
| 77 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.