简体   繁体   中英

Facebook Login/Registration with Codeigniter - user data

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);
            }
        }
    }
} 
$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM