CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Facebook Project Idea.

 



cuboidgraphix
User

Oct 30, 2009, 10:38 AM

Post #1 of 6 (3440 views)
Facebook Project Idea. Can't Post

Hello guys,
I'm trying to write a simple perl program to log into my facebook account and post a specific url to vampire wars, after logging in. After redirecting to the URL, I want to get the website response and print it on my screen.

I don't really have the slightest Idea how to start. Can anybody help me or direct me to some tutorials?


cuboidgraphix
User

Oct 30, 2009, 1:33 PM

Post #2 of 6 (3431 views)
Re: [cuboidgraphix] Facebook Project Idea. [In reply to] Can't Post

Hey guys ... after some digging I found a script here (http://developeronline.blogspot.com/2008/10/using-perl-against-facebook-part-i.html) that could be helpful but I get an error. Anyone know why I get this error?

Can't call method "content" on an undefined value at ./script.pl line 41.

Below is my code.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Cookies;

my $email; #stores our mail
my $password; #stores our password
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';

$email = 'user\@hotmail.com'; #read the login e-mail
$password = 'mypasswd'; #read the password

chomp($email); #remove last line
chomp($password);

my %postLoginData; #necessary post data for login
$postLoginData{'email'}=$email;
$postLoginData{'pass'}=$password;
$postLoginData{'persistent'}=1;
$postLoginData{'login'}='Login';

our $response; #holds the response the HTTP requests
#set the headers, let's make this a Firefox browser!
our @header = ('Referer'=>'http://www.facebook.com', 'User-Agent'=>$user_agent);

our $cookie_jar = HTTP::Cookies->new(file=>'fbkCookies.dat',autosave=>1, ignore_discard=>1);

our $browser = LWP::UserAgent->new; #init browser
$browser->cookie_jar($cookie_jar);

$browser->get('http://www.facebook.com/login.php',@header);

#here we actually login!
$browser->post('https://login.facebook.com/login.php',\%postLoginData,@header);

#was login successful?
if($response->content =~ /Incorrect Email/)
{
print "Login Failed...Quitting..\n";
}
else {
print "..and we are in!";
#let's go to the homepage
#$response = $browser->get('http://www.facebook.com/home.php',@header);
}



cuboidgraphix
User

Nov 1, 2009, 11:50 AM

Post #3 of 6 (3397 views)
Re: [cuboidgraphix] Facebook Project Idea. [In reply to] Can't Post

Can anyone help please.... atleast in getting my my script to log in.

I would really appreciate any help.


FishMonger
Veteran / Moderator

Nov 1, 2009, 1:24 PM

Post #4 of 6 (3392 views)
Re: [cuboidgraphix] Facebook Project Idea. [In reply to] Can't Post

The error message is telling you that the $response object was not defined.

Try changing:

Code
$browser->get('http://www.facebook.com/login.php',@header);


To:

Code
$response = $browser->get('http://www.facebook.com/login.php',@header);



cuboidgraphix
User

Nov 2, 2009, 11:48 AM

Post #5 of 6 (3372 views)
Re: [FishMonger] Facebook Project Idea. [In reply to] Can't Post

Thanks for the reply FishMonger. You are always the one to help and for that I am grateful.

The line in reference to the error code is..


Code
if($response->content =~ /Incorrect Email/)


FYI... I tried taking off the comment to the line you stated and I still got the same error. Line 41 is the line I stated above.


FishMonger
Veteran / Moderator

Nov 2, 2009, 12:53 PM

Post #6 of 6 (3369 views)
Re: [cuboidgraphix] Facebook Project Idea. [In reply to] Can't Post

Why are you using the our keyword when declaring $response instead the my keyword? our declares a global var and my declares a lexical var.

After that declaration, $response is never assigned a value, so when you use it in the if(...) conditional, it will generate the warning that you received.


Quote
FYI... I tried taking off the comment to the line you stated and I still got the same error.


Actually, I was referring to the one that wasn't commented out. Based on the code you posted, that would be line 33.


Code
our $browser = LWP::UserAgent->new; #init browser  
$browser->cookie_jar($cookie_jar);

$response = $browser->get('http://www.facebook.com/login.php',@header);


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives