我正在使用facebook sdk v4,我似乎无法获得电子邮件地址。这是我的代码。我搜索了互联网上的每一个链接并尝试了所有方法。还尝试了不同的脚本,但我仍然收到空电子邮件。这是我的代码。
<div ng-repeat="hello in worlds" | filter:searchQuery | orderBy: sortOrder"
我使用了/* 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*/
//1.Stat Session
session_start();
//check if users wants to logout
if($_REQUEST['logout']==1){
unset($_SESSION['fb_token']);
}
//2.Use app id,secret and redirect url
$app_id = 'xxxxxxxxxx';
$app_secret = 'xxxxxxxxxxxxxxx';
$redirect_url='http://someurl.com/';
//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
$logout = 'http://dryvr.co/fb/?logout=1';
//4. if fb sess exists echo name
if(isset($sess)){
//store the token in the php session
$_SESSION['fb_token']=$sess->getToken();
//create request object,execute and capture response
$request = new FacebookRequest($sess,'GET','/me');
// from response get graph object
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::classname());
// use graph object methods to get user details
$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{
//else echo login
echo '<a href="'.$helper->getLoginUrl(array('email')).'" >Login with facebook</a>';
}
,但仍然无法访问该电子邮件地址,并且它返回了空白电子邮件。我该怎么办?想法?
答案 0 :(得分:1)
在这里查看我的答案:
您需要指定希望从v2.4开始的Graph API返回的每个字段,例如
null
这完全在Facebook文档中。