From ae9048bb74fb0f1b8add3c86b8a10748d30f6977 Mon Sep 17 00:00:00 2001 From: mitty Date: Sat, 11 Sep 2010 02:07:55 +0000 Subject: [PATCH 1/1] * from http://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 --- get_oauth.pl | 29 +++++++++++++++++++++++++++++ nt_bot.pl | 20 ++++++++++++++++++++ twitbot.pl | 11 +++++++++++ 3 files changed, 60 insertions(+) create mode 100755 get_oauth.pl create mode 100755 nt_bot.pl create mode 100755 twitbot.pl 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 を更新するテストですよー'); -- 1.7.9.5