这是facebook php sdk中的登录系统,它会发生什么事情要求基本权限然后当用户通过他的Facebook帐户允许它存储他的脸书ID和电子邮件然后通过会话在索引中显示这个fbid和电子邮件,但它没有正常工作虽然fbid来了坚果电子邮件未来它显示空白
<?php
session_start();
require_once("autoload.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/FacebookAuthorizationException.php');
require_once('Facebook/GraphObject.php');
require_once('Facebook/GraphUser.php');
require_once('Facebook/GraphSessionInfo.php');
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' );
use Facebook\FacebookSession; use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest; use Facebook\FacebookResponse;
use Facebook\FacebookSDKException; use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException; use Facebook\GraphObject;
// init app with app id and secret
FacebookSession::setDefaultApplication( ' 332325566667346','30adsfsdf7sdf87df6s7df87sdf76dsfd16' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://localhost/bb/fbconfig.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
}
// see if we have a session
if ( isset( $session ) ) {
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
$graphObject = $response->getGraphObject();
$email = $graphObject->getProperty('email');
echo $email;
} else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl);
}
?>
答案 0 :(得分:1)
您不是在登录过程中要求提供电子邮件权限:
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email'));
来源:https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl
附注:使用自动加载器或无数的需要语句,而不是两者;)(虽然Autoloader是智能选项)。