Reputation: 1057
I have 2 very simple scripts:
<?php
require_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxx',
'secret' => 'yyyyyyyyyyyyyyyyyyyy',
'cookie' => true,
));
?>
and
<?php
require_once 'config.php';
/* Get a valid session */
$session = $facebook->getSession();
$me = null;
if($session) {
/* Check if session is valid */
$me = $facebook->api('/me');
}
if ($me) {
echo 'User is logged in and has a valid session';
}
else {
echo 'Session expired or user has not logged in yet.
Redirecting...';
echo '<script> top.location.href="'.$facebook->getLoginUrl()
.'";</script>';
}
?>
Why do I get Fatal error: Call to undefined method Facebook::getSession() in C:\wamp\www\jt1\index.php on line 4?
Upvotes: 1
Views: 9874
Reputation: 254944
There is no getSession()
method in modern facebook PHP SDKm use getUser()
instead.
And see sample at https://github.com/facebook/php-sdk/blob/master/examples/example.php
Upvotes: 10
Reputation: 5
I think there is something wrong when you transport the array variable to get a instance!
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxx',
'secret' => 'yyyyyyyyyyyyyyyyyyyy',
***'cookie' => true,***
));
you should not have comma at the end. you can use "'cookie' => true"
Upvotes: -2
Reputation: 9891
$facebook variable is NOT visible to your second script. To prove this, move the logic from the first script that defines $facebook and put it into the second script. It should all begin working.
Upvotes: 0