Last active
December 19, 2015 01:08
-
-
Save c18t/5873171 to your computer and use it in GitHub Desktop.
Twitter API叩くときにいつもつかってるやつ。 require "twitter_agent.pl";
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.010; | |
use Net::Twitter::Lite::WithAPIv1_1; | |
sub twitter_agent { | |
my ($conf_app, $conf_user) = @_; | |
my $nt = Net::Twitter::Lite::WithAPIv1_1->new(%$conf_app, useragent_args => { timeout => 10 }); | |
$nt->access_token($conf_user->{token}); | |
$nt->access_token_secret($conf_user->{token_secret}); | |
my ($pin, @userdata); | |
while (not ($nt->{authorized} = !!eval { $nt->verify_credentials; })) { | |
say 'please open the following url and allow this app, then enter PIN code.'; | |
say $nt->get_authorization_url(); | |
print 'PIN: '; chomp($pin = <STDIN>); | |
@{$conf_user}{qw/token token_secret user_id screen_name/} = $nt->request_access_token(verifier => $pin); | |
$nt->{config_updated} = 1; | |
} | |
return $nt; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment