2010-09-08
PlaggerのPublish::TwitterをOAuth対応に
既に誰かがやっている気もしなくも無いが
--- Plugin/Publish/Twitter.pm 2010-07-03 00:26:00.000000000 +0900 +++ Plugin/Publish/Twitter.pm 2010-09-08 03:18:25.000000000 +0900 @@ -18,34 +18,32 @@ sub initialize { my($self, $context) = @_; my %opt = ( + traits => ['API::REST', 'OAuth'], username => $self->conf->{username}, password => $self->conf->{password}, ); - for my $key (qw/ apihost apiurl apirealm/) { + for my $key (qw/apihost apiurl apirealm consumer_key consumer_secret/) { $opt{$key} = $self->conf->{$key} if $self->conf->{$key}; } - $self->{twitter} = Net::Twitter->new(%opt); + my $nettwitter = Net::Twitter->new(%opt); + if ($self->conf->{access_token} and $self->conf->{access_token_secret}) { + $nettwitter->access_token($self->conf->{access_token}); + $nettwitter->access_token_secret($self->conf->{access_token_secret}); + } + $self->{twitter} = $nettwitter; }
サンプルのconfig.yaml抜粋
- module: Publish::Twitter
config:
username: dankogai
# password: base64::a29nYWlkYW4=
consumer_key: ***
consumer_secret: ***
access_token: ***
access_token_secret: ***
templatize: 1
maxlength: 139
コメント
トラックバック - http://subtech.g.hatena.ne.jp/otsune/20100908
