我正在尝试使用本教程中的代码:http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter通过facebook登录:我的控制器代码如下:
<?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));
}
}
在调用登录后,我将被重定向到facebook,询问权限并重定向到我的应用程序但是我总是得到不正确的消息字符串,这意味着用户没有连接。那么我做错了什么?