php - getUser returning 0 facebook sdk -
i trying make login facebook on codeigniter app. have login button takes them grant permissions , redirects them page should display facebook information in array, getuser keeps returning 0, after log in.
i have no clue start looking errors first dive facebook sdk
here 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 login
<h1>login!</h1> <a href='main/facebook_request'> connect facebook </a>
Comments
Post a Comment