AnyEvent-Twitter
view release on metacpan or search on metacpan
lib/AnyEvent/Twitter.pm view on Meta::CPAN
my $config = JSON::decode_json($json_text);
my $ua = AnyEvent::Twitter->new(%$config);
my $cv = AE::cv;
# GET request
$cv->begin;
$ua->get('account/verify_credentials', sub {
my ($header, $response, $reason) = @_;
say $response->{screen_name};
$cv->end;
});
# GET request with parameters
$cv->begin;
$ua->get('account/verify_credentials', {
include_entities => 1
}, sub {
my ($header, $response, $reason) = @_;
say $response->{screen_name};
$cv->end;
});
# POST request with parameters
$cv->begin;
$ua->post('statuses/update', {
status => 'ããã¯ã«ã»ã¸ã¨ ã¡ãã¬ãã'
}, sub {
my ($header, $response, $reason) = @_;
say $response->{user}{screen_name};
$cv->end;
});
# verbose and old style
$cv->begin;
$ua->request(
method => 'GET',
api => 'account/verify_credentials',
sub {
my ($hdr, $res, $reason) = @_;
if ($res) {
print "ratelimit-remaining : ", $hdr->{'x-ratelimit-remaining'}, "\n",
"x-ratelimit-reset : ", $hdr->{'x-ratelimit-reset'}, "\n",
"screen_name : ", $res->{screen_name}, "\n";
} else {
say $reason;
}
$cv->end;
}
);
$cv->begin;
$ua->request(
method => 'POST',
api => 'statuses/update',
params => { status => 'hello world!' },
lib/AnyEvent/Twitter.pm view on Meta::CPAN
use utf8;
$ua->post(
'statuses/update_with_media',
[
status => 'æ¡',
'media[]' => [ undef, $filename, Content => $loaded_image_binary ],
],
sub {
my ($hdr, $res, $reason) = @_;
say $res->{user}{screen_name};
}
);
=head2 request
These parameters are required.
=over 4
lib/AnyEvent/Twitter.pm view on Meta::CPAN
Passed callback will be called with C<$header>, C<$response>, C<$reason> and C<$error_response>.
If something is wrong with the response from Twitter API, C<$response> will be C<undef>.
On non-2xx HTTP status code, you can get the decoded response via C<$error_response>.
So you can check the value like below.
my $callback = sub {
my ($header, $response, $reason, $error_response) = @_;
if ($response) {
say $response->{screen_name};
} else {
say $reason;
for my $error (@{$error_response->{errors}}) {
say "$error->{code}: $error->{message}";
}
}
};
=back
=head2 parse_timestamp
C<parse_timestamp> parses C<created_at> timestamp like "Thu Mar 01 17:38:56 +0000 2012".
It returns L<Time::Piece> object. Its timezone is localtime.
( run in 1.150 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )