开发者

Facebook connect login problem

I am trying to have a connect button on my site. Once开发者_如何学编程 the user has clicked the facebook login button, the pop up will ask the user to enter the authentication detail and the parent window will either redirect or refresh the page and the login button became a logout button.

My problem is when a user clicked the connect button from the popup, the popup page will redirect to my canvas page rather than closed the popup instead.


Many people have posted this issue, if you have done everything else right, the reason for this is xd_receiver file was not read by the fb.

You need to make sure that where your fb connect button is, you specify the correct path to xd_receiver.html file somewhere on bottom of that page. Something like below:

<script type="text/javascript">
    FB.init("your api key here", "xd_receiver.htm");
</script>

It is even better and easier to put the xd_receiver file on your site's root folder and specify it with full domain url like this:

<script type="text/javascript">
    FB.init("your api key here", "http://www.yoursite.com/xd_receiver.htm");
</script>


Here's a sample of facebook connect, login and logout, works very well, Also make sure you add your site url under your app settings -> Website - > Site URL:

Facebook connect login problem

<!DOCTYPE html> 
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> 
        <head> 
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
            <title>Facebook Connect Sample</title> 
        </head> 
        <body> 
            <div id="fb-root"></div> 
            <script> 
            window.fbAsyncInit = function() {
                FB.init({
                  appId  : 'YOUR APP ID',
                  status : true, // check login status
                  cookie : true, // enable cookies to allow the server to access the session
                  xfbml  : true  // parse XFBML
                });

            /* All the events registered */
            FB.Event.subscribe('auth.login', function(response) {
                // do something on login
                login();
            });
            FB.Event.subscribe('auth.logout', function(response) {
                // do something on logout
                logout();
            });

            FB.getLoginStatus(function(response) {
                if (response.session) {
                    // logged in and connected user, someone you know
                    login();
                }
            });
        };

      /* Loading the JS SDK Asynchronously - Refer: https://developers.facebook.com/docs/reference/javascript/ */
      (function() {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());

    function login(){
        window.location = "http://google.com"; // Redirect to Another Page.

        /* Show User's Name 
        FB.api('/me', function(response) {
            document.getElementById('login').style.display = "block";
            document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";
        });
        */
    }
    function logout(){ 
        document.getElementById('login').style.display = "none";
    }
    </script> 
    <p><fb:login-button autologoutlink="true"></fb:login-button></p> 
        <div id="login" style ="display:none"></div> 
</body> 
</html>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜