Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- //included file and use
- $app_id = 'xxx';
- $app_secret = 'xxx';
- FacebookSession::setDefaultApplication($app_id, $app_secret);
- $helper = new FacebookRedirectLoginHelper("`http://example/facebook4.0`/", $app_id, $app_secret);
- try
- {
- $session = $helper->getSessionFromRedirect();
- }
- catch(FacebookRequestException $ex) { }
- catch(Exception $ex) { }
- $loggedIn = false;
- if (isset($session))
- {
- if ($session)
- {
- $loggedIn = true;
- try { //logged here and get data
- $user_profile = (new FacebookRequest(
- $session, 'GET', '/me'
- ))->execute()->getGraphObject(GraphUser::className());
- print_r($user_profile); //print data
- }
- catch(FacebookRequestException $e)
- {
- echo "Exception occured, code: " . $e->getCode();
- echo " with message: " . $e->getMessage();
- }
- }
- }
- if(!$loggedIn) //if user is not online // get link and add scope
- {
- $loginUrl = $helper->getLoginUrl(array('public_profile','email'));
- echo "<a href='$loginUrl'>Login With Facebook</a>";
- }
- else
- {
- print_r($user_profile); //logout link is generated here
- echo '<br><br><a href="index.php">Logout</a>'; //print to sceen
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement