pushkidman Posted May 7, 2013 Share Posted May 7, 2013 Hi! I am trying to put Facebook SDK to work. I had this code, which I slighly modified, from some internet tutorial: <?php $fbconfig['appid'] = "..."; $fbconfig['secret'] = "..."; $fbconfig['baseurl'] = "..."; $user = null; //facebook user uid try { include_once "facebook.php"; } catch (Exception $o) { error_log($o); } // Create our Application instance. $facebook = new Facebook(array( 'appId' => $fbconfig['appid'], 'secret' => $fbconfig['secret'], )); //print $facebook->getAccessToken() . '<br/>'; $user = $facebook->getUser(); $loginUrl = $facebook->getLoginUrl( array( 'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown', 'redirect_uri' => $fbconfig['baseurl'] ) ); if ($user) { if (isset($_GET['publish'])) { try { $publishStream = $facebook->api("/$user/feed", 'post', array( 'message' => "...", 'link' => '...', 'picture' => '...', 'name' => 'iPlay, iWin', 'description' => '...' ) ); //as $_GET['publish'] is set so remove it by redirecting user to the base url } catch (FacebookApiException $e) { d($e); } $redirectUrl = $fbconfig['baseurl'] . '?success=1'; header("Location: $redirectUrl"); } //fql query example using legacy method call and passing parameter try { $fql = "select name, hometown_location, sex, pic, pic_square, pic_big from user where uid=" . $user; $param = array( 'method' => 'fql.query', 'query' => $fql, 'callback' => '' ); $fqlResult = $facebook->api($param); print_r($fqlResult); $fql = "select url, real_height from profile_pic where id=" . $user; $param = array( 'method' => 'fql.query', 'query' => $fql, 'callback' => '' ); $fqlResult = $facebook->api($param); } catch (Exception $o) { d($o); } } ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>FB Test</title> </head> <body> <?php if (!$user) { ?> <a href="<?= $loginUrl ?>">Facebook Login</a> <?php } else { ?> <div><a href="<?= $facebook->getLogoutUrl(); ?>">Facebook Logout</a></div> <div>You are in! <a href="?publish=1">Share your details with us</a>!</div> <?php } ?> <?php if ($_GET['success']) : ?> <div>Check you FB wall!</div> <?php endif; ?> </body> </html> There are two troubles I have with this code: 1. When I am logged in with Facebook and I go to this page, I still have to connect to FB manually via $loginUrl. Is this OK in terms of SDK? Or am I doing something wrong? 2. When I click on logout URL, nothing happens on the page. It seems to log me out properly out of my actual FB account, but on the page $user object still exists. Sometimes I have to click logout URL several times, before I actually see changes on the page. Why is that? Thanks in advance for any sort of help! Link to comment https://forums.phpfreaks.com/topic/277767-facebook-php-sdk-loginlogout-problems/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.