0

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

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254

2 Answers2

3

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

Mayfield Four
  • 95
  • 3
  • 9
0

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!

Robbie
  • 17,605
  • 4
  • 35
  • 72
  • i have a bug when i use Fatal error: Uncaught CurlException: 77: error setting certificate verify locations: CAfile: C:\wamp\www\project\application\libraries/fb_ca_chain_bundle.crt CApath: none thrown in C:\wamp\www\project\application\libraries\base_facebook.php on line 967 – Jany Warner Aug 22 '12 at 08:44
  • In which case, different issue: http://stackoverflow.com/questions/8994059/facebook-application-development-using-php-sdk may help? You'll need to edit base_facebook.php to add the curl options in the makerequest() function – Robbie Aug 22 '12 at 09:22