参考サイトをコピペして,実行してみる
#!/usr/bin/perl
use strict;
use Net::Twitter;
use utf8;
binmode STDOUT, ":utf8";
my $consumer_key = "<<<YOUR OWN consumer key>>>";
my $consumer_secret = "<<<YOUR OWN consumer secret>>>";
my $access_token = "<<<YOUR OWN access token>>>";
my $access_token_secret = "<<<YOUR OWN access token secret>>>";
my $handle = Net::Twitter->new({
traits => [qw/OAuth API::REST API::Search/],
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
access_token => $access_token,
access_token_secret => $access_token_secret});
#do_search($_) foreach @ARGV;
my $msg = "てすと投稿です";
my $handle = Net::Twitter->new({
traits => [qw/OAuth API::REST/],
consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
access_token => $access_token,
access_token_secret => $access_token_secret});
my $ret = $handle->update({status=>$msg});
print "Cannot post!!" unless $ret;
sub do_search {
my $term = shift;
my @results;
my $rs = $handle->search({q=>$term, lang=>"ja", page=>1, rpp=>100});
if (ref $rs eq 'HASH' && exists $rs->{results}) {
if (@{$rs->{results}}) {
print_post($_) foreach @{$rs->{results}};
}
}
}
sub print_post {
my $t = shift;
print "$t->{from_user} (on $t->{created_at}) $t->{text}\n";
}