2012-10-21 187 views
0

我正在使用Facebook的JavaScript的SDK用戶登錄,然後PHP SDK的其他進程。 這是我的示例代碼:即使用戶登錄Facebook,登錄按鈕顯示

<?php 
require_once('AppInfo.php'); 
require 'src/facebook.php'; 
$facebook = new Facebook(array(
'appId' => '*****', 
'secret' => '*****', 
)); 
// See if there is a user from a cookie 
$user = $facebook->getUser(); 
if ($user) { 
try { 
// Proceed knowing you have a logged in user who's authenticated. 
$user_profile = $facebook->api('/me'); 
} catch (FacebookApiException $e) { 
// If the call fails we check if we still have a user. The user will be 
// cleared if the error is because of an invalid accesstoken 
if (!$facebook->getUser()) { 
    header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI'])); 
    exit(); 
} 
} 
} 
?> 
<!DOCTYPE html> 
<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head> 
<title>Facebook App</title> 
<h1>Facebook App</h1> 
</head> 
<body> 
<div id="fb-root"></div> 
<script type="text/javascript">    
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId: '<?php echo $facebook->getAppID() ?>', 
     cookie: true, 
     xfbml: true, 
     status: true, 
     channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/fb/channel.html' 
    }); 

    FB.Event.subscribe('auth.login', function(response) { 
     window.location.reload(); 
    }); 
     FB.Canvas.setAutoGrow(); 
    }; 
     // Load the SDK Asynchronously 
    (function(d, s, id) { 
    var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) return; 
    js = d.createElement(s); js.id = id; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    fjs.parentNode.insertBefore(js, fjs); 
    }(document, 'script', 'facebook-jssdk')); 

</script> 
<?php if (isset($basic)) { ?> 
<h1>Hi</h1> 

    <div> 
    <h1>Welcome Hero</h1> 
    <p class="tagline"> 
     This is your app 
    </p> 
    </div> 
<?php } else { ?> 
<div> 
    <h1>Welcome Villian</h1> 
    <div class="fb-login-button" data-scope="user_likes,user_photos,publish_stream"></div> 
    </div> 
    <?php echo $user_profile[id]; 
echo "hhhh";} ?> 
</body> 
    </html> 

問題是,我總是看到else部分運行。即使用戶登錄後,它也會顯示else部分。 有人可以請幫我

回答

0

這是在PHP SDK中的問題。 使用js sdk以及phpsdk

+0

你有任何工作示例如何使用js sdk和php sdk tofather – Pratik