我有2个非常简单的脚本:
<?php
require_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxx',
'secret' => 'yyyyyyyyyyyyyyyyyyyy',
'cookie' => true,
));
?>
Run Code Online (Sandbox Code Playgroud)
和
<?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>';
}
?>
Run Code Online (Sandbox Code Playgroud)
为什么我会收到致命错误:在第4行的C:\ wamp\www\jt1\index.php中调用未定义的方法Facebook :: getSession()?
zer*_*kms 10
getSession()现代facebook PHP SDKm中没有方法可以使用getUser().
请参阅https://github.com/facebook/php-sdk/blob/master/examples/example.php上的示例