2015-01-01 98 views
1

這裏是我的代碼:Facebook登錄SDK PHP 4.0的錯誤登錄

<?php 

session_start(); 

require_once('Facebook/FacebookSession.php');  
require_once('Facebook/FacebookRedirectLoginHelper.php');  
require_once('Facebook/FacebookRequest.php');  
require_once('Facebook/FacebookResponse.php');  
require_once('Facebook/FacebookSDKException.php');  
require_once('Facebook/FacebookRequestException.php');  
require_once('Facebook/FacebookAuthorizationException.php');  
require_once('Facebook/GraphObject.php');  
require_once('Facebook/GraphUser.php');  
require_once('Facebook/GraphSessionInfo.php'); 

use Facebook\FacebookSession;  
use Facebook\FacebookRedirectLoginHelper;  
use Facebook\FacebookRequest;  
use Facebook\FacebookResponse;  
use Facebook\FacebookSDKException;  
use Facebook\FacebookRequestException;  
use Facebook\FacebookAuthorizationException;  
use Facebook\GraphObject;  
use Facebook\GraphUser; 
use Facebook\GraphSessionInfo; 

$id = 'xxxxx'; 

$secret = 'xxxxx'; 

FacebookSession::setDefaultApplication($id, $secret); 

$helper = new FacebookRedirectLoginHelper('http://da-404.hol.es/FD/index.php'); 

try{ 

    $session = $helper->getSessionFromRedirect(); 

}catch(Exception $e){ 

} 

if(isset($_SESSION['token'])){ 

    $session = new FacebookSession($_SESSION['token']); 

    try{ 

     $session->Validate($id, $secret); 

    }catch(FacebookAuthorizationException $e){ 

     $session = ''; 
    } 

} 
if(isset($session)){ 

    $_SESSION['token'] = $session->getToken(); 

    echo "Login Successful<br>"; 

    $request = new FacebookRequest($session, 'GET', '/me'); 

    $response = $request->execute(); 

    $graph = $response->getGraphObject(GraphUser::className()); 

    echo "Hi " . $graph->getName(); 
} 

else{ 

echo "<a href = " . $helper->getLoginUrl() . ">Login With Facebook</a>"; 

} 

即使我登錄與FB,我的FB名不會出現。

iamge:http://prntscr.com/5n6iud

我的名字不會出現,甚至連登錄令牌秀...

什麼問題?

回答

0

您確定自己的php 錯誤報告已打開嗎?

原因當我執行你的代碼與我的應用程序的細節我得到這個致命的錯誤,說它缺少幾個類。

Fatal error: Class 'Facebook\Entities\AccessToken' not found in [...location] 

您需要的行use Facebook\FacebookSession;之前,以下neccessary類添加到您的代碼,它應該是工作。

require_once('Facebook/HttpClients/FacebookHttpable.php'); 
require_once('Facebook/HttpClients/FacebookCurl.php'); 
require_once('Facebook/HttpClients/FacebookCurlHttpClient.php'); 
require_once('Facebook/Entities/AccessToken.php'); 
require_once('Facebook/Entities/SignedRequest.php');