开发者

Facebook Connect Javascript API failing to maintain connected state after page reloads

开发者 https://www.devze.com 2022-12-26 10:45 出处:网络
I have a Facebook Connect site using the Javascript API - I\'m not using any FBML tags. It was working fine until a couple of days ago and now I have a problem with reloading the page while the user i

I have a Facebook Connect site using the Javascript API - I'm not using any FBML tags. It was working fine until a couple of days ago and now I have a problem with reloading the page while the user is logged in.

The user can log in fine, and I can get the user's Facebook ID. They can refresh the page and they're still logged in (and I still get the ID). But if they refresh the page again (and subsequently), then FB.Connect.get_loggedInUser() always returns 'None', rather than the Facebook ID, even though FB.Connect.get_status().waitUntilReady() has said they're logged in.

Here's my basic code... can anyone see anything wrong?

FB_RequireFeatures(['Api'], function() {
    FB.init('MY_API_KEY', '/xd_receiver.htm', {});

    FB.ensureInit(function() {
        FB.Connect.get_status().waitUntilReady( function( status ) {
            switch (status) {
                case FB.ConnectState.connected:
                    FB.Connect开发者_JS百科.requireSession(function() {
                        if (FB.Connect.get_loggedInUser()) {
                            var uid = FB.Connect.get_loggedInUser();
                            // Some more stuff here with the user's ID, displaying info in the page, etc.
                        }
                    }
                    break;
                case FB.ConnectState.appNotAuthorized:
                case FB.ConnectState.userNotLoggedIn:
                    // Display FB Connect button in page.
            }
        });
    });
});

Is there something wrong with that? I can't work out how to ensure I get the user's logged in ID. Many thanks.


So, after much testing with various apps and domains and... it seems there was some conflict going on between the JavaScript Facebook code and some pyFacebook code in the Django back-end. Some confusion between the sessions stuff (yet to be figured out) was causing Safari to throw errors. So, we don't know the solution, but the JavaScript code above should, on its own, work fine.

0

精彩评论

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

关注公众号