我目前正在为我的网页上的facebook连接登录页面工作。
但我一直在接受未定义的方法'第24行的错误消息:
$session = $facebook->getSession();
当我删除第24行时,一切似乎都顺利进行。
因为我正在http://www.9lessons.info/2011/01/facebook-graph-api-connect-with-php-and.html和http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/上学习教程 - 它让我感到难过!
错误消息是
Fatal error: Call to undefined method Facebook::getSession() in C:\xampp\htdocs\kite\index.php on line 24
请帮忙。提前谢谢了。这是我的代码:
<?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();
?>
答案 0 :(得分:10)
这是一个老问题,但记录在案:
要获得快速解决方案,请将
getSession()
的所有引用替换为getUser()
示例:
$session = $facebook->getSession();
它应该说:
$session = $facebook->getUser();
答案 1 :(得分:1)
检查您所包含的库。确保你有最新版本
请在此处查看已接受的答案:Facebook require_login not working
答案 2 :(得分:0)
此外,如果您不想编辑代码,您可能希望恢复为2.x sdk。