1
내 사이트에 facebook connect를 통합하려고합니다. 페이스 북에 로그인하고 가입하면 이벤트가 시작되고 response.status는 'connected'를 반환합니다. 그런 다음 페이지를 새로 고침하지만 사용자 데이터가 없습니다. 내가 수동으로 페이지를 새로 고침 경우에만 i는 사용자 정보에 로그인을받을 수 있나요사용자 ID 및 정보를 얻으려면 페이지를 2 번 다시로드해야합니다.
내 코드는 다음과 같습니다
$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>
가 (당신이 너무 빨리 페이지를 새로 고침 아마이