1

I'm trying to use the code from this Tutorial: http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter to do login via facebook: My controller code looks like:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

 class User extends CI_Controller {

public function __construct()
{
    parent::__construct(); 
}   

function index() {
    $this->loginByFacebook();
}

function facebook() {
    $this->load->library('fb_connect');
    if (!$this->fb_connect->user_id) {
        echo 'not ok';
    }
    else 
    {
        $fb_uid = $this->fb_connect->user_id;
        $fb_usr = $this->fb_connect->user;
        print_r($fb_usr); // Printing to show all available variables
        // Do your processing here after login. May be you can check if first time user then can register in your database. 
        echo 'ok';          
    }

}

function loginByFacebook() {
    $this->load->library('fb_connect');
    $param['redirect_uri'] = site_url("user/facebook");
    $param['scope'] = 'email, publish_stream,user_birthday,offline_access'; // Set the required access here
    redirect($this->fb_connect->getLoginUrl($param));
}
}

After calling the login I'll be redirected to facebook, asked for permissions and redirected to my application but then I get always the not ok message string which means, that the user is not connected. So what am I doing wrong?

4

0 回答 0