NAME
AnyEvent::Twitter - A thin wrapper for Twitter API using OAuth
SYNOPSIS
use utf8;
use Data::Dumper;
use AnyEvent;
use AnyEvent::Twitter;
my $ua = AnyEvent::Twitter->new(
consumer_key => 'consumer_key',
consumer_secret => 'consumer_secret',
access_token => 'access_token',
access_token_secret => 'access_token_secret',
);
# if you use eg/gen_token.pl, simply as:
#
# use JSON;
# use Perl6::Slurp;
# my $json_text = slurp 'config.json';
# my $config = decode_json($json_text);
# my $ua = AnyEvent::Twitter->new(%$config);
my $cv = AE::cv;
$cv->begin;
$ua->request(
api => 'account/verify_credentials',
method => 'GET',
sub {
my ($hdr, $res, $reason) = @_;
unless ($res) {
print $reason, "\n";
}
else {
print "ratelimit-remaining : ", $hdr->{'x-ratelimit-remaining'}, "\n",
"x-ratelimit-reset : ", $hdr->{'x-ratelimit-reset'}, "\n",
"screen_name : ", $res->{screen_name}, "\n";
}
$cv->end;
}
);
$cv->begin;
$ua->request(
api => 'statuses/update',
method => 'POST',
params => {
status => '(#`ω´)クポー クポー',
},
sub {
print Dumper \@_;
$cv->end;
}
);
$cv->begin;
$ua->request(
url => 'http://api.twitter.com/1/statuses/update.json',
method => 'POST',
params => {
status => '(#`ω´)クポー クポー',
},
sub {
print Dumper \@_;
$cv->end;
}
);
$cv->recv;
DESCRIPTION
AnyEvent::Twitter is a very thin wrapper for Twitter API using OAuth.
NOTE :
With the removal of basic authentication, the API of this module is different from older version.
Be careful to upgrade if you are using older version.
METHODS
new
All arguments are required. If you don't know how to obtain these parameters, take a look at eg/gen_token.pl and run it.
- consumer_key
- consumer_secret
- access_token
- access_token_secret
request
These parameters are required.
- api or url
-
The api parameter is a shortcut option.
If you want to specify the API url, the url parameter is good for you. The format should be 'json'.
The api parameter will be internally processed as:
$url = 'http://api.twitter.com/1/' . $opt{api} . '.json';
You can check the api option at Twitter API Wiki
- method
-
Investigate the HTTP method of Twitter API that you want to use. Then specify it. GET/POST methods are allowed.
- callback
-
This module is AnyEvent::http_request style, so you have to pass the coderef callback.
$hdr, $response and $reason will be returned. If something is wrong with the response, $response will be undef. So you can check the value like below.
sub { my ($hdr, $res, $reason) = @_; unless ($res) { print $reason, "\n"; } else { print $res->{screen_name}, "\n"; } }
CONTRIBUTORS
AUTHOR
punytan <punytan@gmail.com>
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.