resolving Fatal error: Call to undefined method Facebook::getSession() during facebook authentication
i am currently working on facebook connect login page for my web page.
but i keep recei开发者_开发知识库ving 'call to undefined method' error message at line 24:
$session = $facebook->getSession();
when i remove line 24 everything seems to run smoothly .
ut as i am following a tutorial at http://www.9lessons.info/2011/01/facebook-graph-api-connect-with-php-and.html and http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/ - its kinda left me stumped!
the error message is
Fatal error: Call to undefined method Facebook::getSession() in C:\xampp\htdocs\kite\index.php on line 24
please help. many thanks in advance. here is my code:
<?php session_start();
//config
include "resources/Connections/kite.php";
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect($hostname_kite, $username_kite, $password_kite) or die(mysql_error());
$db = mysql_select_db($database_kite, $con) or die(mysql_error());
//include out functions file giving us access to the protect() function made earlier
include "resources/php/functions.php";
//setup facebook connect
require 'resources/facebook/src/facebook.php';
$facebook = new Facebook(array(
'appId' => $appid_kite,
'secret' => $secret_kite,
));
// Get User ID
$user = $facebook->getUser();
// Let's see if we have an active session
$session = $facebook->getSession();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
ob_start();
?>
This is an old question but for the record:
For a fast solution replace all references to
getSession()
withgetUser()
Example:
$session = $facebook->getSession();
it should say:
$session = $facebook->getUser();
ref: Upgrade to PHP SDK v3.0.0
Also, if you dont wish to edit your code, you might wish to revert to a 2.x sdk.
https://github.com/facebook/php-sdk/zipball/v2.1.2
精彩评论