Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <?php session_start(); // added in v4.0.0 require_once
  2. 'facebook/autoload.php';
  3. use FacebookFacebookSession;
  4. use FacebookFacebookRedirectLoginHelper;
  5. use FacebookFacebookRequest;
  6. use FacebookFacebookResponse;
  7. use FacebookFacebookSDKException;
  8. use FacebookFacebookRequestException;
  9. use FacebookFacebookAuthorizationException;
  10. use FacebookGraphObject;
  11. use FacebookEntitiesAccessToken;
  12. use FacebookHttpClientsFacebookCurlHttpClient;
  13. use FacebookHttpClientsFacebookHttpable; // init app with app id and secret
  14. FacebookSession::setDefaultApplication('id','secret key');
  15. // login helper with redirect_uri
  16. $helper = new FacebookRedirectLoginHelper('http://localhost//myaap/facebook/fbconfig.php');
  17. try { $session = $helper->getSessionFromRedirect(); }
  18. catch( FacebookRequestException $ex )
  19. { // When Facebook returns an error
  20. } catch( Exception $ex )
  21. {
  22. // When validation fails or other local issues
  23. }
  24. // see if we have a session
  25. if ( isset( $session ) ) { // graph api request for user data
  26. $request = new FacebookRequest( $session, 'GET', '/me' );
  27. $response = $request->execute(); // get response
  28. $graphObject = $response->getGraphObject();
  29. $fbid = $graphObject->getProperty('id'); // To Get Facebook ID
  30. $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
  31. $femail = $graphObject->getProperty('email'); // To Get Facebook email ID /* ---- Session Variables -----*/
  32. $_SESSION['FBID'] = $fbid;
  33. $_SESSION['FULLNAME'] = $fbfullname;
  34. $_SESSION['EMAIL'] = $femail;
  35. /* ---- header location after session ----*/
  36. header("Location: index.php"); }
  37. else {
  38. $loginUrl = $helper->getLoginUrl();
  39. header("Location: ".$loginUrl);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement