我正在做一个本地 Facebook 项目。但是当我去 localhost 时,他每次都开始重定向到localhost/?code=xxxx(xxxx 是很长的随机字符)。
我的代码是:
require_once('sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'MY_APP_ID',
'secret' => 'MY_APP_SECRET',
'sharedSession' => true,
'trustForwarded' => true,
'cookie' => true
));
$user_id = $facebook->getUser();
if ($user_id) {
try {
// Fetch the viewer's basic information
$basic = $facebook->api('/me','GET');
} catch (FacebookApiException $e) {
if (!$facebook->getUser()) {
//header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
$user_id = null;
}
}
}
if(!$user_id) {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email,publish_actions'
));
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit();
}
...
提前致谢。