decadence

個人のメモ帳

perlでtwitter

twitter公式からアプリ用の情報を取得します.(省略)
.config.ymlに以下のように記述
パスワードなど入っているのでchmod 600 .config.ymlとかにしときましょう.

consumer_key: "~~~~~~~~~~~"
consumer_secret: "~~~~~~~~~~~"
access_token: "~~~~~~~~~~~"
access_token_secret: "~~~~~~~~~~~"

yamlファイルは最後に改行が必要なので注意.
実際に呟いてみるサンプル

#!/opt/local/bin/perl -w

use utf8;
use strict;
use YAML::Tiny;
use Net::Twitter;

my $configFile = '.config.yml';
my $config = (YAML::Tiny->read($configFile))->[0] ||
    die "error_yaml : ", YAML::Tiny->errstr;
my $twit = Net::Twitter->new(
    traits => [qw/OAuth API::REST/],
    consumer_key => $config->{"consumer_key"},
    consumer_secret => $config->{"consumer_secret"},
    access_token => $config->{"access_token"},
    access_token_secret => $config->{"access_token_secret"},
    );

$twit->update('perlからtwitterを更新するテスト') ||
    die "error_twit_update : ", $!;

__END__

登録したアプリを連動させたアカウントで確かめてみる.出来ました.

院試前日…