2011-07-30 4 views
0

사용자가 checkbook facebook을 통해 페이스 북을 통해 로그인하지 않은 경우이 코드를 사용하여 사용자가 페이스 북을 통해 로그인 할 수 있습니다.페이스 북에 게시하지 않고 새로 고침하는 방법

if($req_user['oauth_provider'] != "facebook") 
{ 
    <input type="checkbox" name="fb_post" id="fb_post" value="1" onclick="facebookPermissionsGrant(); return false;">} 
?> 

는 사용자가 페이스 북의 쇼 체크 박스를 통해 로그인하면 검사 : 사용자가 페이스 북을 통해 로그인하고 checbox을 확인하고 페이스 북에서 사용자 이름과 암호를 입력하지 않은 경우 난 데

if($req_user['oauth_provider'] == "facebook" && $CONFIG['fb_status'] == 1) { 
<input type="checkbox" name="fb_post" id="fb_post" value="1" checked> 
} 

문제입니다. 상자를 다시 확인하려면 페이지를 새로 고쳐야합니다. 아약스 또는 jquery에있는 방법으로 페이지를 새로 고치지 않아도되고 사용자가 로그인 한 경우 체크 박스가 표시됩니다.

답변

0

예, 있습니다. Facebook의 Javascript API에는 FB.Event.Subscribe가 있는데, 사용자의 로그인 상태가 변경 될 때 자바 스크립트에 알립니다.

예 :

window.fbAsyncInit = function() { 
    FB.init({ 
     appId : 'YOURAPPID', 
     status : true, // check login status 
     cookie : true, // enable cookies to allow the server to access the session 
     xfbml : true, // parse XFBML 
     channelUrl : 'http://www.yourdomain.com/channel.html', // Custom Channel URL 
     oauth : true //enables OAuth 2.0 
    }); 

    // retrieve the login status. 
    FB.getLoginStatus(function(response) { 
     if (response.authResponse) update_user_is_connected(); 
     else update_user_is_not_connected(); 
    }); 

    // This will be triggered as soon as the user logs into Facebook (through your site) 
    FB.Event.subscribe('auth.login', function(response) { 
     update_user_is_connected(); 
    }); 
}; 

현재 FB.Event.subscribe에 대한 자세한 내용을보실 수 있습니다 : http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

관련 문제