开发者

Post to facebook how to get responce without refreshing

开发者 https://www.devze.com 2023-03-24 05:18 出处:网络
I have this code if user is not logged in through facebook on check show facebook for user to log in through facebook.

I have this code if user is not logged in through facebook on check show facebook for user to log in through facebook.

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

If us开发者_C百科er is logged in through facebook show checkbox checked:

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

Problem i am having is if user is not logged in through facebook and checks the checbox and enter username and password on facebook. He has to refresh the page again to see that box checked. Is there a way in ajax or in jquery so that i dont have to refresh the page and if user logged in it will show box checked?


Yes, there is. Facebook's Javascript API has got FB.Event.Subscribe, which notifies your javascript when the user's login status changes.

Example:

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();
    });
};

You can read more about FB.Event.subscribe here: http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

0

精彩评论

暂无评论...
验证码 换一张
取 消