我目前正在为我的网页上的facebook连接登录页面工作.
但我一直在第24行接收'调用未定义的方法'错误消息:
$session = $facebook->getSession();
Run Code Online (Sandbox Code Playgroud)
当我删除第24行时,一切似乎都顺利进行.
UT为我下面的教程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
Run Code Online (Sandbox Code Playgroud)
请帮忙.提前谢谢了.这是我的代码:
<?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();
?>
Run Code Online (Sandbox Code Playgroud)
Igo*_*rra 10
这是一个古老的问题,但为了记录:
对于一个快速的解决方案替换所有引用
getSession()与getUser()
例:
$session = $facebook->getSession();
Run Code Online (Sandbox Code Playgroud)
它应该说:
$session = $facebook->getUser();
Run Code Online (Sandbox Code Playgroud)