我需要通过Facebook登录。登录后, -(void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results
{
NSLog(@"result::%@",results);
}
,email
,fbid
,firstname
和lastname
等用户的基本信息将存储在本地数据库中。但我没有从图API中获得sex
。
SDK版本是4.0.0 回调代码是 -
email
没有错误,但仅打印session_start();
// added in v4.0.0
require_once 'autoload.php';
require_once("connection.php");
require_once("functions.inc.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\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication( 'app id','secret' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://dsbangladesh.com/fbconfig.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest($session, 'GET', '/me?fields=id,name,gender,email,first_name,last_name' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
$fbfname = $graphObject->getProperty('name'); // To Get Facebook First name
$fblname = $graphObject->getProperty('last_name');
$sex = $graphObject->getProperty('sex');
echo $fbid;
echo $femail;
echo $sex;
} else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl);
}
和'名称',但不打印fbid
。