<?php
require_once('facebook.php');
$config = array(
'appId' => 'xxxxx',
'secret' => 'xxxxx',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?php
if($user_id) {
try {
$user_profile = $facebook->api('/me','GET');
echo "Name: " . $user_profile['name'];
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
echo "1";
error_log($e->getType());
error_log($e->getMessage());
}
} else {
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
echo "2";
}
?>
</body>
</html>
当我访问 mysite.com/fbconect.php 时,它是一个带有 LOGIN 链接的白页。当我单击登录时,它将进入 Facebook 页面登录。登录后,我返回 mysite.com/fbconect.php 然后显示,登录链接再次回显“1”。mysite.com 的 URL 变成了 mysite.com/fbconect.php?xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx。我的代码有什么问题?