I’m playing with a simple PERL script to post updates to my Twitter account.
#!/usr/bin/perl use LWP::UserAgent; my $output = shift @ARGV; my $browser = LWP::UserAgent->new; my $url = 'http://twitter.com/statuses/update.json'; #print "Verify Credentials\n"; $browser->credentials('twitter.com:80', 'Twitter API', 'TWTR_ACCNT', 'TWTR_PSWD'); $response = $browser->get("http://twitter.com/account/verify_credentials.json"); #print $response->code." ".$response->message."\n"; #print "Update\n"; my $response = $browser->post($url, {status => $output}); #print $response->code." ".$response->message."\n";
The only magic is the LWP::UserAgent module.
When you run it from the command line, the only argument is the status update to Twitter. This could be useful for programatic updates to Twitter from devices or monitoring services. The script is easily modified to support account information from the command-line, but this would appear in a process list on a shared machine and would be a security risk. Industrial strength applications would require connection validation.
% tweet.pl tweet_message_of_140_chars_or_fewer
I’m writing a home security application based on this idea.
What will you do with Twitter on the command-line?
(See also: twitter.com)
(See also: Twitter API Wiki)
(See also: perl.org)