Tag: status

Facebook-Status-2.0 announced!

by Matt Danger on Feb.10, 2009, under Announcements, Perl, Shell Scripting, 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!

Leave a Comment :, , , more...

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!

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');
2 Comments :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Send me a message on AIM!

Friends

Read what I read...