Update Your Facebook Status from the Command Line
by Matt Danger on November 24, 2008
The Facebook Developer Platform doesn’t give us the ability to set a user’s status so I decided to write my own method that would allow Facebook users to update their status messages without having to log into the website.
The first version that I wrote in 2006 was a little complicated. The script had to connect to several Facebook pages and collect cookies and challenge codes that were necessary to login and update the user’s status.
Facebook changed their login and status update mechanisms in version 2.0 breaking my original script. I’ve rewritten it to work with Facebook 2.0. It is now actually shorter because Facebook uses the user’s homepage as the central information area.
Any feedback is welcome. I plan to implement this in other utilities soon. Enjoy!
Updated on May 6, 2010 to version 2.1
#!/usr/bin/perl -w #=============================================================================== # # Facebook status script v2.1 # # This script allows you to update your Facebook status from the shell. # # Copyright (C) 2010 Matt West <matt at mattdanger dot net> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # For a copy of the GNU General Public License visit <http://www.gnu.org/licenses/>. # #=============================================================================== # Be sure you have installed the LWP and Crypt::SSLeay packages from CPAN use LWP; use HTTP::Cookies; use Term::ReadKey; use strict; # General vars my $login; my $password; my $status; my $auth_key; my $response; my $user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6"; my @header = ( 'Referer' => 'http://www.facebook.com/', 'User-Agent' => $user_agent); my $cookie_jar = HTTP::Cookies->new( file => 'cookies.dat', autosave => 1, ignore_discard => 1); my $browser = LWP::UserAgent->new; $browser->cookie_jar($cookie_jar); # Get login information & the status message to send. print "Facebook login name: "; $login = <>; chomp($login); print "Password: "; ReadMode('noecho'); $password = ReadLine(0); chomp($password); ReadMode 0; print "\nYour status (Facebook appears to have a 232 character limit): "; $status = <>; chomp($status); print "\nSending... "; #================================================ # Login and get auth key #================================================ $response = $browser->post('https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php', ['email' => $login, 'pass' => $password, 'login' => 'Log In'], @header); $cookie_jar->extract_cookies( $response ); $cookie_jar->save; $response = $browser->get('http://m.facebook.com/a/home.php', @header); $auth_key = $response->content; $auth_key =~ s/\n//g; $auth_key =~ s/^.*name="post_form_id" value="//; $auth_key =~ s/".*$//; #================================================ # Submit the status update #================================================ @header = ('Referer' => 'http://m.facebook.com/a/home.php', 'User-Agent' => $user_agent, 'Host' => 'm.facebook.com'); $response = $browser->post('http://m.facebook.com/a/home.php?re974fcaf&refid=7&rbb94a931', ['fb_dtsg' => 'jYNZj', 'post_form_id' => $auth_key, 'status' => $status, 'update' => 'Share'], @header); # Did we do good here? if ($response->content eq '') { print "Done!\n\n"; } else { print "An error occurred while setting your profile status.\n\n"; } # Now that we're done we can delete the cookies.dat file. exec('rm cookies.dat');
February 10th, 2009 on 1:33 pm
[...] Matt Danger on Feb.10, 2009, under Uncategorized I have updated my original Facebook status script to work with Facebook [...]
May 6th, 2010 on 3:37 pm
[...] by Matt Danger on May 06, 2010 I have updated my original Facebook status script to version 2.1. Grab it from here. [...]