大家好,我在整合我的脸书应用程序时遇到问题。我创建了一个应用程序和一个本地应用程序,它将连接到我的Facebook应用程序,从用户获取详细信息。检查下面的代码:
<?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 = 'xxxx';
$secret = 'xxx;
FacebookSession::setDefaultApplication($id, $secret);
$helper = new FacebookRedirectLoginHelper('http://localhost/facebook/');
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>";
}
?>
现在问题是当我点击使用Facebook登录时出现此错误:
致命错误:类&#39; Facebook \ Entities \ AccessToken&#39;在第74行的C:\ wamp \ www \ facebook \ Facebook \ FacebookSession.php中找不到
我怎样才能让它发挥作用?任何帮助将不胜感激。
答案 0 :(得分:0)
确保您使用的是最新版本的Facebook PHP SDK,并更改您的代码包括以下内容:
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' );
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/FacebookOtherException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/GraphUser.php' );
require_once( 'Facebook/GraphSessionInfo.php' );
use Facebook\HttpClients\FacebookHttpable;
use Facebook\HttpClients\FacebookCurl;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\Entities\AccessToken;
use Facebook\Entities\SignedRequest;
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookOtherException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;
use Facebook\GraphSessionInfo;