我正在尝试使用Facebook登录按钮构建一个网站,但是当您点击登录按钮时,它会将您带到我的login.php页面,该页面只是空的。据我所知,getLoginUrl只是空的。这是我的代码:
FacebookSession::setDefaultApplication(FB_APP_ID, FB_APP_SECRET);
$helper = new FacebookRedirectLoginHelper(FB_REDIRECT_URI);
if(isset($_GET['type']) && $_GET['type'] == 'facebook' ){
$fb_url = $helper->getLoginUrl(array('email'));
header('Location: ' . $fb_url);
}
$session = $helper->getSessionFromRedirect();
if(isset($_SESSION['token'])){
$session = new FacebookSession($_SESSION['token']);
try{
$session->validate(FB_APP_ID, FB_APP_SECRET);
}catch(FacebookAuthorizationException $e){
echo $e->getMessage();
}
}
$data = array();
if(isset($session)){
$_SESSION['token'] = $session->getToken();
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::className());
$data = $graph->asArray();
$id = $graph->getId();
$image = "https://graph.facebook.com/".$id."/picture?width=100";
$data['image'] = $image;
if($user_obj->fb_login($data)){header('Location: home.php');}
else{header('Location: index.php');}
}
有谁知道我的代码有什么问题?