我正在尝试使用codeigniter应用在facebook上登录。我有一个登录按钮,让他们授予权限,然后将它们重定向到应该在数组中显示他们的Facebook信息的页面,但是即使我登录后,getUser也会保持返回0。
我不知道从哪里开始寻找错误,因为这是我第一次潜入facebook sdk
这是我的代码:
PHP
Facebook连接库:
<?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 {
}
}
}
?>
我的主要功能
<?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;
}
}
}
链接登录
<h1>Login!</h1>
<a href='main/facebook_request'> Connect with facebook </a>