1
我正在嘗試在我的網站上集成facebook連接。一旦我登錄Facebook並訂閱,事件將觸發並且其response.status返回「連接」。然後我重新加載頁面,但我沒有得到任何用戶數據。如果我手動刷新頁面,則只能做我的用戶信息獲取登錄需要重新加載頁面2次才能獲得用戶ID和信息
我的代碼是:
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
//print htmlspecialchars(print_r($user_profile, true));
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
}
}
<div id="fb-root"></div>
<?php if ($user) { ?>
Your user profile is
<pre>
<?php print htmlspecialchars(print_r($user_profile, true)) ?>
</pre>
<?php } //else { ?>
<fb:login-button></fb:login-button>
<?php //} ?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response) {
alert("status " + response.status);
alert('reload');
window.location.reload();
}
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
請幫我解決這個