【发布时间】:2012-06-11 12:13:32
【问题描述】:
我在 codeigniter 下使用 facebook connect。身份验证后我想重定向控制器的成功方法 这是我的控制器:
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('Facebook_model');
}
function index()
{
$fb_data = $this->session->userdata('fb_data');
$data = array(
'fb_data' => $fb_data,
);
$this->load->view('welcome', $data);
}
function topsecret()
{
$fb_data = $this->session->userdata('fb_data');
if((!$fb_data['uid']) or (!$fb_data['me']))
{
redirect('welcome');
}
else
{
$data = array(
'fb_data' => $fb_data,
);
$this->load->view('topsecret', $data);
}
}
function success()
{
$this->load->view('welcome_message');
}
}
我的 facebook api 访问模型:
class Facebook_model extends CI_Model {
public function __construct()
{
parent::__construct();
$config = array(
'appId' => '261066574000678',
'secret' => ' 79e11f65449988965362f58e9a4aabd7',
'fileUpload' => true, // Indicates if the CURL based @ syntax for file uploads is enabled.
);
$this->load->library('Facebook', $config);
$user = $this->facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
$profile = null;
if($user)
{
try {
// Proceed knowing you have a logged in user who's authenticated.
$profile = $this->facebook->api('/me?fields=id,name,link,email');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$fb_data = array(
'me' => $profile,
'uid' => $user,
'loginUrl' => $this->facebook->getLoginUrl(
array(
'scope' => 'email,user_birthday,publish_stream', // app permissions
'redirect_uri' => 'https://sanjay.localhost.com/index.php/welcome/success' // URL where you want to redirect your users after a successful login
)
),
'logoutUrl' => $this->facebook->getLogoutUrl(),
);
$this->session->set_userdata('fb_data', $fb_data);
}
}
因为我在 localhost 主机上对此进行测试,所以我还编辑了我的主机文件并将我的 localhost 主机名更改为 sanjay.localhost.com.redirect 发生但没有发生..我认为可能是因为 querystring.when 重定向发生重定向 uri是
=">https://sanjay.localhost.com/index.php/welcome/success?state=ff5712299510defa&code=AQCaD-FAd1shuW#=
我不明白如何处理查询字符串中的状态和代码。
请帮忙。
【问题讨论】:
-
它是否重定向回欢迎/成功?使用 facebook 进行身份验证后,发生了什么?是否显示任何错误?
-
@Gavin 重定向发生,但显示此网页不可用,浏览器地址如下:sanjay.localhost.com/index.php/welcome/… dnt 知道如何处理此查询字符串
-
查看
uri_protocol文件中的uri_protocol设置。尝试将其设置为每个可用值(有关可用选项,请参阅上面的 cmets),然后转到失败的 URL。我在我的所有网站上都使用 CodeIgniter,在混合用户友好的 url 和包含查询字符串值的 url(即通过查询字符串返回值的贝宝付款)时,我从来没有遇到过问题,所以只需找出有效的方法;) -
@Gavin ya 但是如何处理这个查询字符串值(状态和代码)。如何在我的成功方法中处理它。请告诉我。我是新手。:(
-
我按照你说的试过了。还是不行:(
标签: facebook codeigniter facebook-graph-api session-state