[PHP] Codeigniter整合Facebook : 登入帳號email取得

  • 496
  • 0
  • PHP
  • 2016-09-12

Codeigniter整合Facebook登入
引用套件:https://puneetk.com/facebook-php-sdk-for-codeigniter

[問題]
登入Facebook 讀取user_profile資料,預設只會抓到id,name
即使登入時有下scope =email
無法取得email等個人公開資訊

 


最重要的email  需要另外呼叫  facebook->api('/me');並傳入參數:
範例如下:
 

        $data['user_profile'] = $this->facebook->api('/me?fields=id,name,gender,picture,email');
        var_dump($data);                    
        $oAuth=new OAuthViewModel();
        $oAuth->loginID=$data['user_profile']['id'];
        $oAuth->loginName=$data['user_profile']['name'];
        $oAuth->loginType="facebook";
        $oAuth->email=$data['user_profile']['email'];
        $oAuth->gender=$data['user_profile']['gender'];
        $oAuth->picture=$data['user_profile']['picture']['data']['url'];