I am trying to login with FB using codeigniter & the FB PHP SDK.
but it keeps giving me the same login with facebook link, it's not catching if the user is logged in, Am I missing anything like sessions or something?
And since we are at it how can I get the extended session & what data should I save to publish to pages while user is offline?
here is my controller:
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);
}
And here is the view:
<!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>