From: mitty Date: Sat, 11 Sep 2010 02:07:55 +0000 (+0000) Subject: * from http://d.hatena.ne.jp/layerzero/20090930/p1 X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftwitter-0.1%4044;p=lab.git * from d.hatena.ne.jp/layerzero/20090930/p1 * get_oauth.pl * nt_bot.pl * from http://www.otchy.net/20090629/making-of-twitter-bot-1/ * twitbot.pl git-svn-id: https://lab.mitty.jp/svn/lab/vendor/twitter@44 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- ae9048bb74fb0f1b8add3c86b8a10748d30f6977 diff --git a/get_oauth.pl b/get_oauth.pl new file mode 100755 index 0000000..6f840ab --- /dev/null +++ b/get_oauth.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use utf8; +use Net::Twitter; + +my $consumer_key = 'CONSUMER_KEY'; +my $consumer_key_secret = 'CONSUMER_KEY_SECRET'; + +my $nt = Net::Twitter->new( + traits => ['API::REST', 'OAuth'], + consumer_key => $consumer_key, + consumer_secret => $consumer_key_secret, +); +print 'access this url by bot account : '.$nt->get_authorization_url."\n"; +print 'input verifier PIN : '; +my $verifier = ; +chomp $verifier; + +my $token = $nt->request_token; +my $token_secret = $nt->request_token_secret; + +$nt->request_token($token); +$nt->request_token_secret($token_secret); + +my($at, $ats) = $nt->request_access_token(verifier => $verifier); + +print "Access token : ".$at."\n"; +print "Access token secret : ".$ats."\n"; diff --git a/nt_bot.pl b/nt_bot.pl new file mode 100755 index 0000000..3fec52e --- /dev/null +++ b/nt_bot.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use utf8; +use Net::Twitter; + +my $consumer_key = 'CONSUMER_KEY'; +my $consumer_key_secret = 'CONSUMER_KEY_SECRET'; +my $access_token = 'ACCESS_TOKEN'; +my $access_token_secret = 'ACCESS_TOKEN_SECRET'; + +my $nt = Net::Twitter->new( + traits => ['API::REST', 'OAuth'], + consumer_key => $consumer_key, + consumer_secret => $consumer_key_secret, +); +$nt->access_token($access_token); +$nt->access_token_secret($access_token_secret); + +my $res = $nt->update({ status => "test tweet!" }); diff --git a/twitbot.pl b/twitbot.pl new file mode 100755 index 0000000..b53c6dc --- /dev/null +++ b/twitbot.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use YAML::Tiny; +use Net::Twitter; + +my $config = (YAML::Tiny->read('config.yml'))->[0]; +my $twit = Net::Twitter->new(username => $config->{'username'}, password => $config->{'password'}); + +$twit->update('Perl から Twiitter を更新するテストですよー');