Facebook Login/Registration with Codeigniter - use

2019-06-07 08:41发布

问题:

I have a problem with the user data - the only data that I recieve after Facebook Login is 'name' and 'id', which is the facebook id of the user. I also need to recieve 'firstname', 'lastname' and 'email.

I'm testing the website at localhost and I've created app in developers.facebook.com

Maybe the problem is that the app is in developing mode and that's why it's not giving me the full data?

Here is my code of taking the user data:

<?php
include(APPPATH.'libraries/facebook/facebook.php');

class Fbconnect extends Facebook {

    public $user = null;
    public $user_id = null;
    public $fb = false;
    public $fbSession = false;
    public $appKey = 0;

    public function Fbconnect() {

        $ci =& get_instance();
        $ci->config->load('facebook', TRUE);
        $config = $ci->config->item('facebook');

        parent::__construct($config);

        $this->user_id = $this->getUser();
        $me = null;
        if($this->user_id) {
            try{
                $me = $this->api('/me');
                $this->user = $me;
            } catch(FacebookApiException $e) {
                error_log($e);
            }
        }
    }
} 

回答1:

$my_profile_info = (new FacebookRequest($session, 'GET', '/me/?fields=id,first_name,last_name,email,picture,gender,location,address,email,hometown'))->execute()->getGraphObject()->asArray();   

Hope this help too in answering your question. Facebook Official Documentation

You could login using the same Facebook ID that you used for APP which will show these data, or you could use Facebook tools such as https://developers.facebook.com/tools/explorer/ to query facebook database.