AnyEvent-Twitter
view release on metacpan or search on metacpan
lib/AnyEvent/Twitter.pm view on Meta::CPAN
=head1 API VERSION
As of version 0.63, L<AnyEvent::Twitter> supports Twitter REST API v1.1.
NOTE: API version 1.0 is already deprecated.
=head1 METHODS
=head2 new
All arguments are required except C<api_version>.
If you don't know how to obtain these parameters, take a look at eg/gen_token.pl and run it.
=over 4
=item C<consumer_key>
=item C<consumer_secret>
=item C<access_token> (or C<token>)
=item C<access_token_secret> (or C<token_secret>)
=item C<api_version> (optional; default: 1.1)
If you have a problem with API changes, specify C<api_version> parameter.
Possible values are: C<1.1> or C<1.0>
=back
=head2 get
=over 4
=item C<< $ua->get($api, sub {}) >>
=item C<< $ua->get($api, \%params, sub {}) >>
=item C<< $ua->get($url, sub {}) >>
=item C<< $ua->get($url, \%params, sub {}) >>
=back
=head2 post
=over 4
=item C<< $ua->post($api, \%params, sub {}) >>
=item C<< $ua->post($url, \%params, sub {}) >>
=item C<< $ua->post($api, \@params, sub {}) >>
=item C<< $ua->post($url, \@params, sub {}) >>
=back
=head3 UPLOADING MEDIA FILE
You can use C<statuses/update_with_media> API to upload photos by specifying parameters as arrayref like below example.
Uploading photos will be tranferred with Content-Type C<multipart/form-data> (not C<application/x-www-form-urlencoded>)
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
=item C<api> or C<url>
The C<api> parameter is a shortcut option.
If you want to specify the API C<url>, the C<url> parameter is good for you. The format should be 'json'.
The C<api> parameter will be internally processed as:
sprintf 'https://api.twitter.com/1.1/%s.json', $api; # version 1.1
sprintf 'http://api.twitter.com/1/%s.json', $api; # version 1.0
You can find available C<api>s at L<API Documentation|https://dev.twitter.com/docs/api>
=item C<method> and C<params>
Investigate the HTTP method and required parameters of Twitter API that you want to use.
Then specify it. GET and POST methods are allowed. You can omit C<params> if Twitter API doesn't require it.
=item callback
This module is L<AnyEvent::HTTP> style, so you have to pass the callback (coderef).
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}";
}
( run in 1.394 second using v1.01-cache-2.11-cpan-b16cb0d3907 )