AnyEvent-Twitter
view release on metacpan or search on metacpan
eg/gen_token.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use JSON;
use AnyEvent;
use AnyEvent::Twitter;
my %p;
print "Register your app at https://dev.twitter.com/apps\n\n";
print "Paste your\n";
$p{consumer_key} = do {
lib/AnyEvent/Twitter.pm view on Meta::CPAN
package AnyEvent::Twitter;
use strict;
use warnings;
use utf8;
use 5.008;
our $VERSION = '0.64';
use Carp;
use JSON;
use URI;
use URI::Escape;
use Digest::SHA;
use Time::Piece;
use AnyEvent::HTTP;
lib/AnyEvent/Twitter.pm view on Meta::CPAN
token_secret => $self->{access_token_secret},
);
my $req_params = {};
if ($method eq 'POST') {
$url = $req->normalized_request_url;
if ($is_multipart) {
my $encoded_params = Data::Recursive::Encode::_apply(
sub { utf8::is_utf8($_[0]) ? Encode::encode_utf8($_[0]) : $_[0] },
{},
$params
);
my $ireq = POST(
$url,
Content_Type => 'multipart/form-data',
Content => [ @$encoded_params ]
);
lib/AnyEvent/Twitter.pm view on Meta::CPAN
__END__
=encoding utf-8
=head1 NAME
AnyEvent::Twitter - A thin wrapper for Twitter API using OAuth
=head1 SYNOPSIS
use utf8;
use Data::Dumper;
use AnyEvent;
use AnyEvent::Twitter;
my $ua = AnyEvent::Twitter->new(
consumer_key => 'consumer_key',
consumer_secret => 'consumer_secret',
token => 'access_token',
token_secret => 'access_token_secret',
);
lib/AnyEvent/Twitter.pm view on Meta::CPAN
=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};
}
use strict;
use utf8;
use Test::More;
use JSON;
use Encode;
use AnyEvent::Twitter;
my $config;
if (-f './xt/config.json') {
open my $fh, '<', './xt/config.json' or die $!;
xt/get_request_token.t view on Meta::CPAN
use strict;
use utf8;
use Test::More;
use Data::Dumper;
use JSON;
use Encode;
use AnyEvent::Twitter;
plan skip_all => 'This test should not be executed by prove'
if $ENV{HARNESS_ACTIVE};
use strict;
use utf8;
use Test::More;
use JSON;
use Encode;
use AnyEvent::Twitter;
my $config;
if (-f './xt/config.json') {
open my $fh, '<', './xt/config.json' or die $!;
xt/request.t view on Meta::CPAN
use strict;
use utf8;
use Test::More;
use JSON;
use Encode;
use AnyEvent::Twitter;
my $config;
if (-f './xt/config.json') {
open my $fh, '<', './xt/config.json' or die $!;
xt/update_with_media.t view on Meta::CPAN
use strict;
use utf8;
use Test::More;
use JSON;
use Encode;
use AnyEvent::Twitter;
my $config;
if (-f './xt/config.json') {
open my $fh, '<', './xt/config.json' or die $!;
xt/update_with_media.t view on Meta::CPAN
$cv->begin;
$ua->get('help/configuration', sub {
my ($hdr, $res, $reason) = @_;
note explain $res;
is $res->{max_media_per_upload}, 1, 'keep watch on a allowed media counts';
$cv->end;
});
{
no utf8;
$cv->begin;
$ua->post('statuses/update_with_media',
[
status => 'ããã¯ã«ã»ã¸ã¨ ' . rand,
'media[]' => [ undef, 'filename', Content => $image_1 ],
], sub {
my ($hdr, $res, $reason) = @_;
is($res->{user}{screen_name}, $screen_name, "account/verify_credentials");
note explain \@_;
$cv->end;
( run in 0.503 second using v1.01-cache-2.11-cpan-49f99fa48dc )