2013-01-25 24 views
8

當我按下登錄按鈕時,我得到了Facebook頁面,我必須授權使用我的Facebook帳戶。在iOS Chrome中的白色頁面的FB重定向問題

在我許可後,它重定向到https://www.facebook.com/dialog/permissions.request並顯示一個空白頁。在Android上,調用「window.FB.login」回調(參見下面的代碼),我可以獲取信息並重定向用戶,但在Windows Phone上它只顯示空白頁面。當我進入我的臉書頁面時,我的網站被註冊到了應用程序列表中。所以註冊確實工作正常。

回答

4

此錯誤是由於不安全的加載facebook js文件造成的。

爲了在您的應用程序中集成Facebook應用程序,您必須遵循Facebook應用程序文檔中指示的步驟。

var fbApi = { 
     init: function() { 
     $.getScript(document.location.protocol + '//connect.facebook.net/en_US/all.js', function() { 
     if (window.FB) { 
      window.FB.init({ 
       appId: MY_APP_ID, 
       status: true, 
       cookie: true, 
       xfbml: false, 
       oauth: true, 
       channelUrl: 'http://www.yourdomain.com/channel.html' 
      }); 

     } 
    }); 
    }, 
    login: function() { 
    /// <summary> 
    /// Login facebook button clicked 
    /// </summary> 
    log("login facebook button clicked"); 

    if (window.FB) { 

     //Windows phone does not enter this method, Android and Iphone do 
     window.FB.login(function (response) { 

      if (response.status) { 
       log('it means the user has allowed to communicate with facebook'); 

       fbAccessToken = response.authResponse.accessToken; 
       window.FB.api('/me', function (response) { 
        //get information of the facebook user. 
        loginService.subscribeSocialUser(response.id, response.first_name, response.last_name, fbAccessToken, "", "FaceBook", fbSucces, fbFail); 

       }); 
      } else { 
       log('User cancelled login or did not fully authorize.'); 

      } 
     }, 
     { scope: 'email' 
     }); 
    } 

} 
}; 

通道URL被添加以解決任何跨瀏覽器問題。 它應指向它指的是JS如下一個HTML文件:

<script src="//connect.facebook.net/en_US/all.js"></script> 

如果一旦在初始化Facebook.js的錯誤已被擊中,你將無法成功登錄。

您可以同步或異步加載java腳本。

(function(d, debug){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document, /*debug*/ false)); 
+0

謝謝。我通過使用php的重定向選項來實現FB。 –