[英]Codeigniter login with facebook return userId 0 , After login success and redirect back to my side
I have developed login facebook app(Facebook SDK) with codeigniter, Firstly, I do in my local. 我已经用codeigniter开发了登录Facebook应用(Facebook SDK),首先,我在本地进行。
It's working well, when do login successful, facebook redirect back by redirect_uri to my side controller,and get userId to query information of user logged. 运行良好,成功登录后,facebook由redirect_uri重定向回我的侧控制器,并获取userId来查询登录用户的信息。
But, when I upload this code to Server side, redirect_uri is worked, but I get return 0 of userId, so , if userId 0, I can't query data of users logged. 但是,当我将此代码上传到服务器端时,redirect_uri起作用了,但是我得到了userId的返回值0,因此,如果userId为0,则无法查询登录用户的数据。
My question is, why userId return 0 , after login succeed? 我的问题是,登录成功后,为什么userId返回0?
Code Controller: 代码控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Setting extends CI_Controller {
public function __construct()
{
$CI = & get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
$this->load->library('facebook', $config);
}
public function index()
{
if($this->form_validation->run() == FALSE){
$this->acc_login();
}else {
redirect('check_session', 'refresh');
}
}
public function acc_login()
{
$user = $this->facebook->getUser();
if($user) {
try {
$user_info = $this->facebook->api('/me');
redirect(base_url());
} catch(FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
}
} else {
$param = array('scope' => 'email,read_stream','redirect_uri' => $my_url);
$data['getURLLogin'] = "<a href=\"".$this->facebook->getLoginUrl($param)."\"><img src=\"".base_url()."public/frontend/images/login-fb.png\" width=\"155\" height=\"25\" /></a>";
}
}
}
?>
Try to add 尝试添加
parse_str( $_SERVER['QUERY_STRING'], $_REQUEST );
before 之前
$user = $this->facebook->getUser();
UPDATE 更新
FB changed the parameter from "redirect_url" to "next" from v2 to v3, and is poooooorly documented. FB将参数从“ redirect_url”更改为“ next”,从v2更改为v3,并进行了详细记录。 Try "next", should work for you.
尝试“下一步”,应该为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.