0

I am trying to make a login with facebook on a codeigniter app. I have a login button that takes them to grant permissions and then redirects them to the page that should display their facebook information in an array, however getUser keeps returning 0, even after I log in.

I have no clue where to start looking for errors as this is my first dive into facebook sdk

Here is my code:

php

Facebook connect library:

<?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 __construct() {
        $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);
            }
        } else {
        }

    }

}

 ?>

My main function

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

class Main extends CI_Controller {
    public function index()
    {
        $this->login();
    }
    public function login() {
        $this->load->library('fbconnect');

        $this->load->view('login');
    }

    public function facebook_request() {

        $this->load->library('fbconnect');
        $data = array(
            'redirect_uri' => 'http://localhost/ci_test/main/handle_facebook_login',
            'scope' => 'email'
        );
        redirect($this->fbconnect->getLoginUrl($data));
    }

    public function handle_facebook_login() {
        $this->load->library('fbconnect');
        if ($this->fbconnect->user) {
            print_r($this->fbconnect->user);
        } else
        {
            echo "Couldn't log in";
            echo "User Id";
            echo $this->fbconnect->user_id;
        }
    }
}

Link To Login

<h1>Login!</h1>
    <a href='main/facebook_request'> Connect with facebook </a>
Wp3Dev
  • 2,001
  • 7
  • 38
  • 54

0 Answers0