Recently, I found a text-based twitter client named "
twidge". It allows me to tweet right from command line. For example, if you want to do a hello world tweet, you run this:
% twidge update "hello world"
I then think it would be a good idea if I can do the same thing with facebook i.e. to update facebook status right from command line. However, when I did search on google, I found nothing.
Well, actually, there is an indirect way by:
- Adding facebook application "Selective Tweet".
- With the same twitter account you use to add "Selective Tweet", whenever you append "#fb" to your tweet, that tweet will also appear on facebook status.
But for many personal reasons, I just dislike this method as the same thing will be put onto both twitter and facebook which is not always what I want.
So what if I want to do it directly...
Recently, I had a chance to try out the Perl module "
WWW::Mechanize" - Handy web browsing in a Perl object. It is a subclass of the well-known
LWP::UserAgent module which is a User Agent module for Perl which we use to write robot, spider and such.
Here is the Perl script I use to update facebook status:
#!/usr/bin/perl
use WWW::Mechanize;
$mech = WWW::Mechanize->new;
$mech->agent_alias('Windows Mozilla');
$base_url = 'http://m.facebook.com';
# {{{ login
$mech->get($base_url);
$response = $mech->submit_form(
fields => {
email => 'your_email_address',
pass => 'facebook_password'
}
);
die $response->status_line unless $response->status_line;
# }}}
while (1) {
print "What's on your mind? : ";
$status = <STDIN>;
$response = $mech->submit_form(
fields => {
status => $status
}
);
die $response->status_line unless $response->status_line;
}
Here is what you will see when you run it:
unsigned_nerd@linuxsucks ~ % fbset
What's on your mind? : it's easier to update facebook status from command line
By the way, isn't it better if I use some Facebook API instead...? Umm... maybe later.