Skip to content

Instantly share code, notes, and snippets.

@SangPetualang
Created June 2, 2011 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SangPetualang/1005585 to your computer and use it in GitHub Desktop.
Save SangPetualang/1005585 to your computer and use it in GitHub Desktop.
facebook for CI 2.0.0
<?php
function __construct()
{
parent::__construct();
//$this->load->model('Facebook_model');
$this->load->library('session');
$config = array(
'appId' => 'xxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxx',
'cookie' => true, // enable optional cookie support
);
$this->load->library('facebook', $config);
$session = $this->facebook->getSession();
$me = null;
$uid = null;
// Session based API call.
if($session)
{
try {
$uid = $this->facebook->getUser();
$me = $this->facebook->api('/me?fields=id,name,link,email');
} catch (FacebookApiException $e) {
error_log($e);
}
}
// Here you could actually use an else to redirect the user to a login page,
// however, CI wont accept by default some URI chars and it will fail
// Instead I recommend using the FBML or the JavaScript SDK
$this->session->set_userdata('fb_me', $me);
$this->session->set_userdata('fb_uid', $uid);
//$this->Facebook_model->get_user();
}
function index()
{
$data['session'] = $this->facebook->getSession();
$data['AppID'] = $this->facebook->getAppId();
$data['logoutUrl'] = $this->facebook->getLogoutUrl();
$data['loginUrl'] = $this->facebook->getLoginUrl();
$data['fb_me'] = $this->session->userdata('fb_me');
$data['fb_uid'] = $this->session->userdata('fb_uid');
$this->load->view($this->theme_path.'facebook_view', $data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment