views:

2413

answers:

3

hi guys, I am having some trouble with my little facebook application, I keep getting this friggin error, "Fatal error: Call to undefined method Facebook::require_login()", now the funny bit is that my exact same code is working for other people, but not for me, here is the code.

<?php
require_once( "facebook-php-sdk/src/facebook.php" );
$api_key = "my_api_key";
$secret = "my_secret_key";

$facebook = new Facebook( $api_key, $secret );
$user_id = $facebook->require_login();

echo "Hello World";
echo "Current logged in as <fb:name uid=\"$user_id\" />";
?>

As you can see it is a simple hello USER application, but for some reason this REFUSES to work for me, so if anyone can help out that would be great, thanx in advance!

+1  A: 

Try adding the require_frame() method there:

require_once( "facebook-php-sdk/src/facebook.php" );
$api_key = "my_api_key";
$secret = "my_secret_key";

$facebook = new Facebook( $api_key, $secret );
$facebook->require_frame();
$user_id = $facebook->require_login();

echo "Hello World";
echo "Current logged in as <fb:name uid=\"$user_id\" />";

It seems to be working fine for me.

Make sure that you are using the latest php client for facebook, also try searching for require_login method in facebook.php class that you are including.

Sarfraz
nope, now I am getting this"Fatal error: Call to undefined method Facebook::require_frame()"
+3  A: 

Are you using the newest version of the PHP sdk?

Facebook::require_login() is a method from the old SDK.

The new SDK (published in conjunction with the Graph API) is not backwards compatible.

The notion of requiring a login doesn't even exist anymore - you just obtain the user's ID as such.

$user_id = $facebook->getUser();
Peter Bailey
The weird thing is, I tried that first, and I got a very similar error!Now it seems to be working though, I'm not getting the error anymore, here is what I am seeing, "Hello World Current logged in as Facebook User", it's not printing the persons name, I am also trying to get his user id, but I am assuming that is also the reason why I am not seeing the name, as it requires the uid to get the users name.
+1  A: 

You can see a very simple introduction on the new facebook SDK here: http://www.phpfour.com/blog/2010/05/quick-start-on-new-facebook-php-sdk-iframe-based/

phpfour
That worked a treat, thanx a million, you truly are a lifesaver! I will most probably be posting some more questions whilst I get acquainted with the new api, so if you wouldn't mind answering a few more newbie questions I would really appreciate it, as your introduction is just about the only one out there that worked for me! haha
Heh heh, thanks! Looking forward to your next questions ;)
phpfour