php 解决致命错误:在 Facebook 身份验证期间调用未定义的方法 Facebook::getSession()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6119856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
resolving Fatal error: Call to undefined method Facebook::getSession() during facebook authentication
提问by methuselah
i am currently working on facebook connect login page for my web page.
我目前正在为我的网页处理 facebook 连接登录页面。
but i keep receiving 'call to undefined method' error message at line 24:
但我一直在第 24 行收到“调用未定义方法”错误消息:
$session = $facebook->getSession();
when i remove line 24 everything seems to run smoothly .
当我删除第 24 行时,一切似乎都运行顺利。
ut as i am following a tutorial at http://www.9lessons.info/2011/01/facebook-graph-api-connect-with-php-and.htmland http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/- its kinda left me stumped!
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/- 它有点让我难住了!
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();
?>
回答by Igor Parra
This is an old question but for the record:
这是一个老问题,但为了记录:
For a fast solution replace all references to
getSession()
withgetUser()
对于一个快速的解决方案替换所有引用
getSession()
与getUser()
Example:
例子:
$session = $facebook->getSession();
it should say:
它应该说:
$session = $facebook->getUser();
回答by Rahul
Also, if you dont wish to edit your code, you might wish to revert to a 2.x sdk.
此外,如果您不想编辑代码,您可能希望恢复到 2.x sdk。