dflow Posted January 16, 2012 Share Posted January 16, 2012 im trying to use the : https://github.com/facebook/php-sdk to get the current logged in user to facebook the problem is that im getting an old session each time. i have an app which is inside a facebook iframe. here is some code i found but it isn't returning the current user: <?php require_once('facebook.php'); // Print an individual cookie echo $_COOKIE["fbsr"]; echo $HTTP_COOKIE_VARS["fbsr"]; // Another way to debug/test is to view all cookies // after the page reloads, print them out if (isset($_COOKIE['cookie'])) { foreach ($_COOKIE['cookie'] as $name => $value) { $name = htmlspecialchars($name); $value = htmlspecialchars($value); echo "$name : $value <br />\n"; } } // Remember to copy files from the SDK's src/ directory to a // directory in your application on the server, such as php-sdk/ // Create our application instance // (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' => 'xxxxxxxxxxxx', 'secret' => 'xxxxxxx', )); // Get User ID $user = $facebook->getUser(); // We may or may not have this data based // on whether the user is logged in. // If we have a $user id here, it means we know // the user is logged into // Facebook, but we don’t know if the access token is valid. An access // token is invalid if the user logged out of Facebook. if ($user) { echo 'user'; try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } // Login or logout url will be needed depending on current user state. if ($user) { $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl = $facebook->getLoginUrl(); } // This call will always work since we are fetching public data. ?> <!doctype html> <html xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <title>php-sdk</title> <style> body { font-family: 'Lucida Grande', Verdana, Arial, sans-serif; } h1 a { text-decoration: none; color: #3b5998; } h1 a:hover { text-decoration: underline; } </style> </head> <body> <h1>php-sdk</h1> <?php if ($user): ?> <a href="<?php echo $logoutUrl; ?>">Logout</a> <?php else: ?> <div> Login using OAuth 2.0 handled by the PHP SDK: <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> </div> <?php endif ?> <h3>PHP Session</h3> <pre><?php print_r($_SESSION); ?></pre> <?php if ($user): ?> <h3>You</h3> <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> <h3>Your User Object (/me)</h3> <pre><?php print_r($user_profile); ?></pre> <?php else: ?> <strong><em>You are not Connected.</em></strong> <?php endif ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/255141-driving-me-nuts-facebook-php-sdk-login-in-iframe-app-tab/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.