我使用codeigniter框架使用的facebook库在mysite中构建facebook登录
登录效果很好,但最后我看到了这个错误
ERROR - 2013-07-29 06:51:51 --> Severity: Notice --> Undefined index: access_token /home/dtworks/public_html/amd/xta2/application/libraries/facebook.php 32
库/ facebook.php
function get_facebook_cookie() {
$CI = & get_instance();
$app_id = $CI->config->item('facebook_app_id');
$application_secret = $CI->config->item('facebook_app_secret');
if (isset($_COOKIE['fbsr_' . $app_id])) {
list($encoded_sig, $payload) = explode('.', $_COOKIE['fbsr_' . $app_id], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
return null;
}
$expected_sig = hash_hmac('sha256', $payload, $application_secret, $raw = true);
if ($sig !== $expected_sig) {
return null;
}
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&client_secret=" . $application_secret . "&redirect_uri=" . "&code=" . $data['code'];
$response = @file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$data['session_key'] = $data['code'];
$data['access_token'] = $params['access_token']; // line 32
return $data;
} else {
return null;
}
}
控制器/ auth_other
// this function to signin with facebook
function fb_signin() {
// load facebook library
$this->load->library('facebook'); // this has been loaded in autoload.php
// get the facebook user and save in the session
$fb_user = $this->facebook->getUser();
if (isset($fb_user)) {
$this->session->set_userdata('facebook_id', $fb_user['id']);
$user = $this->user_model->get_user_by_sm(array('facebook_id' => $fb_user['id']), 'facebook_id');
if (sizeof($user) == 0) {
redirect('auth_other/fill_user_info', 'refresh');
} else {
// simulate what happens in the tank auth
$this->session->set_userdata(array('user_id' => $user[0]->id, 'username' => $user[0]->username,
'status' => ($user[0]->activated == 1) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED));
// $this->tank_auth->clear_login_attempts($user[0]->email); //can't run this when doing FB
$this->users->update_login_info($user[0]->id, $this->config->item('login_record_ip', 'tank_auth'), $this->config->item('login_record_time', 'tank_auth'));
redirect('auth', 'refresh');
}
} else {
echo 'cannot find the Facebook user';
}
}