Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. //included file and use
  5.  
  6. $app_id = 'xxx';
  7. $app_secret = 'xxx';
  8. FacebookSession::setDefaultApplication($app_id, $app_secret);
  9. $helper = new FacebookRedirectLoginHelper("`http://example/facebook4.0`/", $app_id, $app_secret);
  10. try
  11. {
  12. $session = $helper->getSessionFromRedirect();
  13. }
  14. catch(FacebookRequestException $ex) { }
  15. catch(Exception $ex) { }
  16.  
  17. $loggedIn = false;
  18.  
  19. if (isset($session))
  20. {
  21. if ($session)
  22. {
  23. $loggedIn = true;
  24. try { //logged here and get data
  25. $user_profile = (new FacebookRequest(
  26. $session, 'GET', '/me'
  27. ))->execute()->getGraphObject(GraphUser::className());
  28.  
  29. print_r($user_profile); //print data
  30.  
  31. }
  32. catch(FacebookRequestException $e)
  33. {
  34. echo "Exception occured, code: " . $e->getCode();
  35. echo " with message: " . $e->getMessage();
  36. }
  37. }
  38. }
  39.  
  40. if(!$loggedIn) //if user is not online // get link and add scope
  41. {
  42. $loginUrl = $helper->getLoginUrl(array('public_profile','email'));
  43. echo "<a href='$loginUrl'>Login With Facebook</a>";
  44. }
  45. else
  46. {
  47. print_r($user_profile); //logout link is generated here
  48. echo '<br><br><a href="index.php">Logout</a>'; //print to sceen
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement