2013-03-20 184 views
0

我似乎無法理解爲什麼我沒有被重定向到適當的頁面。它當然存在。沒有重定向我,屏幕彈出並在一秒鐘後消失。Facebook登錄按鈕沒有重定向

<div id='fb-root'></div> 
<script> 
window.fbAsyncInit = function() 
{ 
    FB.init({ 
     appId: 'ID', 
     status: true, 
     cookie: true, 
     xfbml: true 
    }); 

    FB.Event.subscribe('auth.login', function(response) 
    { 
     window.location = '/fb_redirect.php'; 
    }); 
}; 

(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=ID'; 
     fjs.parentNode.insertBefore(js, fjs); 
    }(document, 'script', 'facebook-jssdk')); 
</script> 

<div class='fb-login-button' data-show-faces='false' scope='email' data-width='200' data-max-rows='1'></div> 

回答

0

而不是做FB.Event.subscriber的,請嘗試以下操作:

FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
     if (typeof response != 'undefined' && typeof response.authResponse != 'undefined') { 
      window.location = '/fb_redirect.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. 
    } 
}); 

該函數將返回connected如果用戶登錄,然後將其重定向到任何網頁你想要的。您可以爲需要首次登錄的用戶保留FB.Event.subscriber函數,並且上面的代碼可用於返回用戶。

+0

如何提示第一次用戶接受我用我的應用程序定義的特定範圍? – Lance 2013-03-20 20:17:19

+0

您可以使用'FB.login()'向他們顯示登錄對話框,但是由用戶來接受範圍並添加應用程序。 – 2013-03-23 13:17:47