Guest User

Untitled

a guest
Jan 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class Facebook_model extends CI_Model {
  2.  
  3. public function get_user() {
  4. $config = array(
  5. 'appId' => 'xxxx',
  6. 'secret' => 'xxxx',
  7. 'cookie' => true, // enable optional cookie support
  8. );
  9.  
  10. $this->load->library('Facebook', $config);
  11.  
  12. $session = $this->facebook->getSession();
  13.  
  14. $me = null;
  15. $uid = null;
  16.  
  17. // Session based API call.
  18. if ($session) {
  19. try {
  20. $uid = $this->facebook->getUser();
  21. $me = $this->facebook->api('/me?fields=id,name,link,email,picture');
  22. } catch (FacebookApiException $e) {
  23. error_log($e);
  24. }
  25. }
  26.  
  27. // Here you could actually use an else to redirect the user to a login page,
  28. // however, CI wont accept by default some URI chars and it will fail
  29. // Instead I recommend using the FBML or the JavaScript SDK to process login and logout
  30.  
  31. $this->session->set_userdata('fb_me', $me);
  32. $this->session->set_userdata('fb_uid', $uid);
  33. }
  34. }
Add Comment
Please, Sign In to add comment