我正在尝试使用 codeigniter 和 FB PHP SDK 登录 FB。
但它一直给我与facebook链接相同的登录信息,如果用户登录它并没有捕捉到,我是否错过了诸如会话之类的东西?
既然我们在这里,我如何才能获得扩展会话以及在用户离线时我应该保存哪些数据以发布到页面?
这是我的控制器:
function __construct () {
parent::__construct();
$this->load->helper('url_helper');
$this->load->add_package_path(APPPATH.'third_party/facebook/');
$this->config->load('facebook', TRUE);
$this->load->library('facebook', array( 'appId' => $this->config->item('appId', 'facebook'), 'secret' => $this->config->item('secret', 'facebook') ) );
}
public function index() {
$data['LoginURL'] = $this->facebook->getLoginUrl( array('scope' => 'manage_pages') );
$data['user'] = $this->facebook->getUser();
if ($data['user']) {
try {
$data['user_profile'] = $this->facebook->api('/me');
$data['AccessToken'] = $this->facebook->getAccessToken();
} catch (FacebookApiException $e) {
// The access token we have is not valid
$data['user'] = null;
}
}
$this->load->view('fb_welcome', $data);
}
这是视图:
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ( $user ): ?>
User <em><?php echo $user ?></em> is Logged in, AccessToken is <?php echo $AccessToken; ?>
<?php print_r($user_profile); ?>
<?php else: ?>
<?php echo anchor($LoginURL, "Login with facebook"); ?>
<?php endif; ?>
</body>
</html>