我正在尝试通过FB登录。如果我没有登录FB,一切正常,但如果我登录FB并点击“通过Facebook登录!”超链接URL已经改变了,就像这个fb2.php?code=AQAlKrGXWS2bhiZ-ZK7UPiDRLdVMjR84jAbxS41kW3I5h5P...
,但我没有登录,如果我没有登录,直到我第二次点击。这很奇怪,不是吗?你能有人帮助我吗?源代码在这里。
<?php session_start();
define('APP_ID', 'my_api_id');
define('APP_SECRET', 'my_app_secret');
define('CANVAS_PAGE', 'http://apps.facebook.com/xxx/');
define('CANVAS_URL', 'http://localhost/xxx/');
require_once 'facebook.php';
$facebook = new Facebook( array('appId' => APP_ID, 'secret' => APP_SECRET, ));
$user = $facebook->getUser();
if(isset($user)) {
try {
xtended_permission)
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = NULL;
}
}
if ($user) { $logoutUrl = $facebook->getLogoutUrl(array('next' =>
"http://metalradio.cz/metalRadioTesting/facebook-sdk/logout.php")); }
else { $loginUrl = $facebook->getLoginUrl( array(
'scope' => 'email' ) ); }
?>
<!doctype html>
<html>
<head>
<title>Facebook login</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
<?php
if(!is_null($user))
echo "Name: " . $user_profile['email'];
?>
<h2>Users authentification via FB</h2>
<?php if ($user):
?>
<a href="<?php echo $logoutUrl;?>">logout!</a>
<?php else:?>
<div>
<a href="<?php echo $loginUrl;?>">login via facebook!</a>
</div>
<?php endif?>
</body>
</html>