php - FACEBOOK SDK v4 is returning blank email adress -
i'm using facebook sdk v4 , can't seem email address. here code. have searched each , every link on internet , tried every thing. tried different scripts still i'm getting null email. here code.
/* 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 logout if($_request['logout']==1){ unset($_session['fb_token']); } //2.use app id,secret , redirect url $app_id = 'xxxxxxxxxx'; $app_secret = 'xxxxxxxxxxxxxxx'; $redirect_url='http://someurl.com/'; //3.initialize application, create helper object , 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 token in php session $_session['fb_token']=$sess->gettoken(); //create request object,execute , capture response $request = new facebookrequest($sess,'get','/me'); // response graph object $response = $request->execute(); $graph = $response->getgraphobject(graphuser::classname()); // use graph object methods 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 $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 facebook</a>'; }
i have used $email = $graph->getproperty('email');
still can not access email address , returning blank email. should do? thoughts?
have @ answer here:
you need specify each field want returned graph api starting v2.4, e.g.
$request = new facebookrequest($sess,'get','/me?fields=id,name,email');
it's in facebook docs.
Comments
Post a Comment