i want capture users' email address when sign in site facebook. have following code:
session_start(); added in v4.0.0 require_once 'autoload.php'; /******function store users' value******/ require_once 'functions.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 app id , secret facebooksession::setdefaultapplication( '*****app id****','***secret key****' ); // login helper redirect_uri $helper = new facebookredirectloginhelper('http://mykadamtala.com/facebook/fbconfig.php' ); try { $session = $helper->getsessionfromredirect(); } catch( facebookrequestexception $ex ) { // when facebook returns error } catch( exception $ex ) { // when validation fails or other local issues } // see if have session if ( isset( $session ) ) { // graph api request user data $request = new facebookrequest( $session, 'get', '/me' ); $response = $request->execute(); // response $graphobject = $response->getgraphobject(); $fbid = $graphobject->getproperty('id'); // facebook id $firstname = $graphobject->getproperty('first_name'); $lastname = $graphobject->getproperty('last_name'); $fbfullname = $graphobject->getproperty('name'); $gender = $graphobject->getproperty('gender'); $femail = $graphobject->getproperty('email'); //this of course not work /* ---- session variables -----*/ $_session['fbid'] = $fbid; $_session['email'] = $femail; //nothing stores here $_session['gender'] = $gender; $_session['fullname'] = $fbfullname; adduser($fbid,$firstname, $lastname, $femail); /* ---- header location after session ----*/ header("location: index.php"); } else { $loginurl = $helper->getloginurl(); header("location: ".$loginurl); }
users' id , gender, first name, last name stored fine. email not captured. searching here got plug script:
$getemail = $helper->getloginurl(array( 'scope' => 'email ));
but confused include , how store email in variable adduser()
function can store email address in database. appreciate lot.
it belongs in last else
block:
... else { $loginurl = $helper->getloginurl(array( 'scope' => 'email' )); header("location: ".$loginurl); }
Comments
Post a Comment