Tag: Facebook
Facebook-Status-2.0 announced!
by Matt Danger on Feb.10, 2009, under Perl, Shell Scripting, Uncategorized, Unix, terminal
I have updated my original Facebook status script to work with Facebook 2.0.
Why is this interesting? Until recently the Facebook Developer Platform didn’t allow the changing of user status messages. This does and can be implemented in other utilities, which I may do in the future. Enjoy!
Update Your Facebook Status from the Command Line
by Matt Danger on Nov.24, 2008, under Perl
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!
#!/usr/bin/perl -w #=============================================================================== # # Facebook status script v2.0 # # This script allows you to update your Facebook status from the shell. # # Copyright (C) 2009 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_message; my $post_form_id; my $profile_id; my $response; my $returned_data; 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 "Enter your Facebook login name: "; $login = <>; chomp($login); print "Enter your password: "; ReadMode('noecho'); $password = ReadLine(0); chomp($password); ReadMode 0; print "\nNow enter your status, Facebook appears to have a 161 character limit:\n\nI... "; $status_message = <>; chomp($status_message); print "\nSending... "; #================================================ # Let's get started. The first thing to do is # to connect to the index and collect some cookies. #================================================ $response = $browser->get('http://www.facebook.com', @header); $cookie_jar->extract_cookies( $response ); #================================================ # Now send the login information #================================================ $response = $browser->post('https://login.facebook.com/login.php?login_attempt=1', ['charset_test' => '€,´,‚Ǩ,¬¥,Ê∞¥,–î,–Ñ', 'locale' => 'en_US', 'persistent' => '1', 'email' => $login, 'pass' => $password, 'pass_placeholder' => 'Password'], @header); $cookie_jar->extract_cookies( $response ); #================================================ # Now that we've logged in let's display our account home page # and grab the profile_id and post_form_id. #================================================ @header = ( 'Host' => 'facebook.com', 'User-Agent' => $user_agent, 'Connection' => 'keep-alive'); $response = $browser->get('http://www.facebook.com/home.php', @header); $cookie_jar->extract_cookies( $response ); $cookie_jar->save; $returned_data = $response->content; $returned_data =~ s/\n//g; # Get the profile_id $profile_id = $returned_data; $profile_id =~ s/^.*<div class="fb_menu_title">//; $profile_id =~ s/<a href="http:\/\/www.facebook.com\/profile.php\?id=//; #" $profile_id =~ s/&.*$//; # Get the post_form_id $post_form_id = $returned_data; $post_form_id =~ s/^.*name="post_form_id" value="//g; #" $post_form_id =~ s/".*$//; #" #================================================ # Finally, submit our status update #================================================ @header = ( 'Referer' => 'http://www.facebook.com/home.php?', 'User-Agent' => $user_agent, 'Host' => 'www.facebook.com'); $response = $browser->post('http://www.facebook.com/updatestatus.php', [ 'profile_id' => $profile_id, 'status' => $status_message, 'home_tab_id' => '1', 'test_name' => 'INLINE_STATUS_EDITOR', 'action' => 'HOME_UPDATE', 'post_form_id' => $post_form_id, 'post_form_id_source' => 'AsynxRequest'], @header); $cookie_jar->extract_cookies( $response ); # Did we do good here? if ( $response->content =~ m/"No error."/ ) { print "Done!\n\n"; } else { my $errorSum = $response->content; my $errorDesc = $response->content; $errorSum =~ s/^.*"errorSummary":"//; #" $errorSum =~ s/".*$//; #" $errorDesc =~ s/^.*"errorDescription":"//; #" $errorDesc =~ s/".*$//; #" print "An error occurred: $errorSum. $errorDesc\n"; } # Now that we're done we can delete the cookies.dat file. exec('rm cookies.dat');