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 {
    print "\tconsumer_key    : ";
    my $key = <STDIN>;
    chomp $key;
    $key;
};

$p{consumer_secret} = do {
    print "\tconsumer_secret : ";
    my $secret = <STDIN>;
    chomp $secret;
    $secret;
};

our %TOKEN;
my $cv = AE::cv;
$cv->begin;
AnyEvent::Twitter->get_request_token(
    consumer_key    => $p{consumer_key},
    consumer_secret => $p{consumer_secret},
    callback_url    => 'oob',
    cb => sub {
        my ($location, $response, $body, $header) = @_;
        %TOKEN = %$response;

        print "\n",
              "Access the authorization URL and get the PIN at \n\n",
              "$location\n\n";

        $cv->end;
    },
);
$cv->recv;

my $pin = do {
    print "\tInput the PIN   : ";
    my $p = <STDIN>;
    chomp $p;
    $p;
};

$cv = AE::cv;
$cv->begin;
AnyEvent::Twitter->get_access_token(
    consumer_key       => $p{consumer_key},
    consumer_secret    => $p{consumer_secret},
    oauth_token        => $TOKEN{oauth_token},
    oauth_token_secret => $TOKEN{oauth_token_secret},
    oauth_verifier     => $pin,
    cb => sub {
        my ($token, $body, $header) = @_;



( run in 3.555 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )