Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Facebook_model extends CI_Model {
- public function get_user() {
- $config = array(
- 'appId' => 'xxxx',
- 'secret' => 'xxxx',
- '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,picture');
- } 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 to process login and logout
- $this->session->set_userdata('fb_me', $me);
- $this->session->set_userdata('fb_uid', $uid);
- }
- }
Add Comment
Please, Sign In to add comment