Facebook在Fb.login之后重定向

时间:2011-04-13 20:57:18

标签: facebook facebook-graph-api

我正在尝试在我的网站上实施FB.login()。我得到“请求权限”窗口,一旦用户接受它,我想将他重定向到我的自定义页面(在同一个域下)。我应该在代码中的哪个位置和如何设置?

 <script>
        //initializing API
        window.fbAsyncInit = function () {
            FB.init({ appId: 'xxx', status: true, cookie: true,
                xfbml: true
            });
        };
        (function () {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        } ());

    function fblogin() {  
        FB.login(function (response) {
            //...
        }, { perms: 'user_birthday,user_location' });
    }
</script>

2 个答案:

答案 0 :(得分:3)

您应该订阅auth.login事件,例如:

window.fbAsyncInit = function() {
    FB.init({ appId: 'xxx', status: true, cookie: true,
        xfbml: true
    });

    FB.Event.subscribe('auth.login', function(resp) {
        window.location = 'http://www.domain.com/custom_page.php';
    });
};

答案 1 :(得分:0)

这对我有用:

<div id='loginmsg'>
<div class="fb-login-button" data-scope="email,publish_stream,read_stream" data-show-faces="true" data-width="720" data-max-rows="1"></div>
</div>


<script>
FB.Event.subscribe('auth.login', function(resp) {        
    $('#loginmsg').html("<h2>...just a moment...</h2>");
    window.location = '/logged-in.html';   
  });

FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
      var uid = response.authResponse.userID;
      var accessToken = response.authResponse.accessToken;
      $('#loginmsg').html("<h2>...just a moment...</h2>");
      window.location = '/logged-in.html';
    }
  });

</script>