我将facebook的SDK添加到我的PHP项目中,并尝试获取用户的数据 但即使我已将所有必需的库文件包含在正确的目录中,我也会收到以下错误。但不管我做什么
Class 'Facebook\HttpClients\FacebookStreamHttpClient' not found in
C:\..\Facebook\FacebookRequest.php
这是我的代码:
<?php
session_start();
require_once( 'lib/Facebook/HttpClients/FacebookHttpable.php');
require_once( 'lib/Facebook/HttpClients/FacebookCurl.php' );
require_once( 'lib/Facebook/HttpClients/FacebookCurlHttpClient.php');
require_once( 'lib/Facebook/FacebookSession.php');
require_once( 'lib/Facebook/FacebookRedirectLoginHelper.php');
require_once( 'lib/Facebook/FacebookRequest.php' );
require_once( 'lib/Facebook/FacebookResponse.php' );
require_once( 'lib/Facebook/FacebookSDKException.php' );
require_once( 'lib/Facebook/FacebookRequestException.php' );
require_once( 'lib/Facebook/FacebookAuthorizationException.php' );
require_once( 'lib/Facebook/GraphObject.php' );
require_once( 'lib/Facebook/GraphSessionInfo.php' );
require_once( 'lib/Facebook/GraphUser.php' );
require_once( 'lib/Facebook/Entities/AccessToken.php');
use Facebook\FacebookHttpable;
use Facebook\FacebookCurl;
use Facebook\FacebookCurlHttpClient;
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\GraphSessionInfo;
use Facebook\GraphUser;
use Facebook\AccessToken;
if(isset($_REQUEST['logout'])){
unset($_SESSION['fb_token']);
}
$app_id = 'xxxxxxxxxxx';
$app_secret = 'xxxxxxxxxx';
$redirect_url='http://localhost/test/ex/fbloginlogout/';
//3.Initialize application, create helper object and get fb sess
FacebookSession::setDefaultApplication($app_id,$app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
$sess = $helper->getSessionFromRedirect();
//check if facebook session exists
if(isset($_SESSION['fb_token'])){
$sess = new FacebookSession($_SESSION['fb_token']);
}
$logout = 'http://localhost/test/ex/newfblogin&logout=true';
if(isset($sess)){
$_SESSION['fb_token']=$sess->getToken();
$request = new FacebookRequest($sess,'GET','/me');
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::classname());
$name = $graph->getName();
$id = $graph->getId();
$image = 'https://graph.facebook.com/'.$id.'/picture?width=300';
$email = $graph->getProperty('email');
echo "hi $name <br>";
echo "your email is $email <br><Br>";
echo "<img src='$image' /><br><br>";
echo "<a href='".$logout."'><button>Logout</button></a>";
}else{
echo '<a href="'.$helper->getLoginUrl(array('email')).'" >Login with facebook</a>';
}