我正在使用php facebook graph api登录facebook,在这里登录facebook后我得到了用户的详细信息,如姓名,身份证,位置,链接。但我无法获得用户的电子邮件ID。我提到了很多这样的例子,但我无法理解如何在我的代码中做到这一点。
这是我的代码:
<?php
/* INCLUSION OF LIBRARY FILEs*/
require_once( 'lib/Facebook/FacebookSession.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/FacebookRedirectLoginHelper.php');
require_once( 'lib/Facebook/FacebookAuthorizationException.php' );
require_once( 'lib/Facebook/GraphObject.php' );
require_once( 'lib/Facebook/GraphUser.php' );
require_once( 'lib/Facebook/GraphSessionInfo.php' );
require_once( 'lib/Facebook/Entities/AccessToken.php');
require_once( 'lib/Facebook/HttpClients/FacebookCurl.php' );
require_once( 'lib/Facebook/HttpClients/FacebookHttpable.php');
require_once( 'lib/Facebook/HttpClients/FacebookCurlHttpClient.php');
/* USE NAMESPACES */
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;
use Facebook\FacebookHttpable;
use Facebook\FacebookCurlHttpClient;
use Facebook\FacebookCurl;
/*PROCESS*/
session_start();
$app_id = '389605751141082';
$app_secret = 'a59a6fb216eafe5e3accc7b95f53c3bc';
$redirect_url='http://parshwatax.com/november/facebook/test.php';
FacebookSession::setDefaultApplication($app_id,$app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
$sess = $helper->getSessionFromRedirect();
if(isset($sess)){
$request = new FacebookRequest($sess, 'GET', '/me');
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::className());
$fname= $graph->getFirstName();
echo "hi $fname";
$lname= $graph->getLastName();
echo "$lname";
$id= $graph->getId();
echo "$id";
$link= $graph->getLink();
echo "$link";
$mail= $graph->getEmail();
echo "$mail";
require_once("connection.php");
$q="select * from `myuser` where `Email`='$mail'";
$r=mysql_query($q);
$row=mysql_fetch_assoc($r);
$uid=$row['Userid'];
echo $uid;
echo "Your are successfully login <a href='http://parshwatax.com/november/fblogincheck.php?a=$uid'>click here</a> to enjoy swapping...!";
}
?>
这是页面的主要部分,我不清楚,但我只需要电子邮件ID。