2017-05-16 67 views
-1

我是Facebook Graph API中的新人..在Facebook Graph API中傳遞電子郵件和用戶生日範圍

我正在使用此代碼,它完美地提取姓名和性別。我想從Facebook獲取電子郵件和出生日期。

<?php 
// added in v4.0.0 
    require_once 'autoload.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('xxxxxx','xxxxxxxxxxxxxxxxxx'); 

    // login helper with redirect_uri 
    $helper = new FacebookRedirectLoginHelper('http://www.xxxxxxxxx.com/'); 

    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'); 
     $response = $request->execute(); 

     // get response 
     $graphObject = $response->getGraphObject(); 
     $fbid = $graphObject->getProperty('id');   // To Get Facebook ID 
     $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name 
     $femail = $graphObject->getProperty('email');  // To Get Facebook email ID 

     /* ---- Session Variables -----*/ 
     $_SESSION['FBID'] = $fbid; 
     $_SESSION['FULLNAME'] = $fbfullname; 
     $_SESSION['EMAIL'] = $femail; 

     /* ---- header location after session ----*/ 
     header("Location: index.php"); 
    }else { 
     $loginUrl = $helper->getLoginUrl(); 
     header("Location: ".$loginUrl); 
    } 

?> 

現在我如何在我的代碼中傳遞電子郵件和用戶生日範圍。 我已經取得了用戶生日和來自Facebook的電子郵件viva我的APP的批准。

回答

相關問題