将用户重定向到我的页面内容

时间:2013-11-19 17:29:07

标签: php facebook

我正在使用Facebook帐户让用户登录我的网站。我成功地做到了,但是,在用户使用Facebook帐户成功登录后,它仍然停留在登录页面上。

我的代码:

    <script>

    (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=1421518261398144";
     fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));


      FB.getLoginStatus(function(response) {
     if (response.status === 'connected') {
      // the user is logged in and has authenticated your
     // app, and response.authResponse supplies
     // the user's ID, a valid access token, a signed
     // request, and the time the access token 
     // and signed request each expir    window.location = "";e

    var uid = response.authResponse.userID;
    var accessToken = response.authResponse.accessToken;
    } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
      window.location = "http://record.comxa.com/server/home.php";
    } else {
    // the user isn't logged in to Facebook.
    }
   });

   </script>

2 个答案:

答案 0 :(得分:0)

您需要添加此代码(将URL替换为您的成功页面URL):

window.location = "URL";

在此代码下方:

  var accessToken = response.authResponse.accessToken;

有了这个,它应该在登录成功时将用户重定向到成功页面。

答案 1 :(得分:0)

您应该将您重定向用户的代码部分添加到第一个 if 块。它应该是这样的:

<script>

        (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
         js = d.createElement(s); js.id = id;
         js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=1421518261398144";
         fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));


        FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        window.location = "http://record.comxa.com/server/home.php";
        } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook, 
        // but has not authenticated your app
        } else {
        // the user isn't logged in to Facebook.
        }
       });

</script>