Perl で Twitter に投稿するのをやってみた
Twitter ボットの作り方 Perl 編 (1) – OTCHY.NET
http://www.otchy.net/20090629/making-of-twitter-bot-1/
こちらのスクリプトを試してみたけれど、うまく動かせなかった。た。
よくわからない。
- twitbot.pl
- config.yml
の 2 つのファイルを
/home/USERNAME/
に置いて、ターミナルから実行するとエラーになる。なっていた。
%./twitbot.pl Can't use an undefined value as an ARRAY reference at ./twitbot.pl line 8.
twitbot.pl の中身は以下のとおり。
#!/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 を更新するテストですよー');
追記
と思ったら、できたー!
config.yml の内容、下記 2 行の最後に改行入れたらうまく動いた。
username: "twitter_user_name" password: "twitter_password"
最後は改行が必要なのかな?よくわかっていないけれど動いたのでひとまずよしとする。