home

Quickies, by Andrea Olivato

text

Creating a Twitter @reply from Perl

How to update your twitter account using Perl, specifying an ‘in reply to’ parameter.

#! /usr/bin/perl

# Configuration
my $TW_USER = "USERNAME";
my $TW_PASS = "PASSWORD";
my $INREPLYTO = "POST_ID"; # Retrieve this from Twitter
my $MESSAGE = "SOMETHING TO SAY";

# Import library and get an User Agent
use LWP::UserAgent;
my $ua = new LWP::UserAgent;

# Set up the request
my $req = new HTTP::Request POST => 'http://twitter.com/statuses/update.xml';

# Authenticating and setting up post data
$req->authorization_basic($TW_USER, $TW_PASS);
$req->content("status=$MESSAGE&in_reply_to_status_id=$INREPLYTO");

# Send the request
my $res = $ua->request($req);

# print $res->status_line; # Uncomment this for debugging

3 years ago

May 18, 2009
Comments (View)
blog comments powered by Disqus