I’m trying to develop a Facebook application, and I have uploaded my index.php file, and I get this error when I run it (I use the new Facebook SDK 3.1.1):
Fatal error: Call to undefined method Facebook::getSession() in /home/onlyimg/public_html/facebook/beworkstar/index.php on line 4
Code
<?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>';
?>
You are using the new PHP-SDK but you haven’t updated your code. Check the latest SDK example.
Here’s a rewrite of your code: