//
you're reading...
howto, scripting, SSO

How to Authenticate against Facebook using Perl

#!/usr/bin/perl -w
#How to Authenticate against Facebook using Perl
#coded by Panagiotis Iliopoulos 20/2/2011
#apt-get install libcrypt-ssleay-perl

use strict;
use LWP::UserAgent;
use HTTP::Cookies;
my $fname="fbkCookies.dat";


if (-e $fname) { unlink $fname;}
my $email=”user@domain name”;
my $password=”yourpassword”;
my $user_agent = 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Ideos Build/FRF91) AppleWebKit/533.1 Mobile Safari/533.1';
my %postLoginData=(
         email=>$email,
         pass=>$password,
         persistent=>1,
         login=>'Login'
);
 my @header = ('Referer'=>'http://www.facebook.com', 'User-Agent'=>$user_agent);
 my $cookie_jar = HTTP::Cookies->new(file=>$fname,autosave=>1, ignore_discard=>1);
 my $browser = LWP::UserAgent->new;
 $browser->cookie_jar($cookie_jar);
 $browser->get('http://www.facebook.com/login.php',@header);
 my $response = $browser->post('https://login.facebook.com/login.php',\%postLoginData,@header);
 my $result=$response->content;
 if (($result =~ /Incorrect Email/) || ($result =~ /Forgot your password/))
 {
   print "\nLogin Failed...\nQuitting..\n";
   exit(1);
 }
 else {
 print "\nSuccess!\n";
 $response = $browser->get('http://www.facebook.com/home.php',@header);
 exit;
 }

 

Discussion

Comments are closed.