简体   繁体   中英

getUser() always return 0 in Codeigniter

I started to create a small application using codeigniter framework and i have dowloaded Facebook connect from github after creating my application inside facebook, at this moment all work alright my only problem is getUser() always return 0

i have create a facebook.php inside application/config/ alse i have extracting facebook.php & base_facebook.php inside application/libraries/

this is my code

class Welcome extends CI_Controller {

    private $data = array();



    public function index() {
        $this->data['loginUrl'] = $this->facebook->getLoginUrl();
        $this->data['userId'] = $this->facebook->getUser();
        $this->load->view('welcome_message', $this->data);
    }

}

in autoload i have :

$autoload['libraries'] = array('database','session','facebook'); 

so why getUser() return 0 and how can i fix this problem thx

on base_facebook.php , find the makeRequest() method, and, inside the function, find this line:

$opts = self::$CURL_OPTS;

Immediately following it, add:

$opts[CURLOPT_SSL_VERIFYPEER] = false; 

or read from here

It does this, sometimes. I've never worked out why, but there is a simple solution that I now always follow.

As opposed to asking for getUser, ask for api(/me) wrapped in a try catch block. If this fails, user is not logged in/token is invalid. If it works the user is logged in, and you get the user id from the resultant array.

You're probably saving a call, as you'll ask for /me anyway. Just remember the try catch for error trapping!

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