3

我正在嘗試使用parse.com Facebook SDK來允許我的用戶使用Fb登錄按鈕登錄到我的網站。Parse.FacebookUtils.logIn只允許通過彈出框登錄Facebook嗎?

我有臺瀏覽器和Safari這個工作不錯,但與創建錯誤討論here IOS瀏覽器的已知問題。

我的調查已經使我得出這樣的結論是Parse.FacebookUtils.logIn類是導致Facebook的彈出窗口中打開,是正確的?

如果是的話,是不是可以打開此作爲一個頁面,而不是一個彈出?這將避免上述錯誤。

我已經建立了一個標準的Facebook登錄工作,但對於解析不起作用解決方法。不知道它是否有可能使用它?這項工作的信息來自here

我也看到了從拉胡爾here作爲一個潛在的解決答案,但我不能確定如何實現,因爲我已經被困在了好久了它

任何幫助將受到歡迎。

function getUserData() { 
    FB.api('/me', function(response) { 
     document.getElementById('response').innerHTML = 'Hello ' + response.name; 
    }); 
} 

window.fbAsyncInit = function() { 
    //SDK loaded, initialize it 
    Parse.FacebookUtils.init({ 
     appId  : '12345', 
     xfbml  : true, 
     version : 'v2.3' 
    }); 


    //check user session and refresh it 
    var uri = encodeURI('http://mysite123.com/user_home.html'); 
    FB.getLoginStatus(function(response) { 
     if (response.status === 'connected') { 
      //user is authorized 
      document.getElementById('loginBtn').style.display = 'none'; 
      getUserData(); 

     } else { 
      //user is not authorized 
     } 
    }); 
}; 

//load the JavaScript SDK 
(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"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 


//add event listener to login button 
document.getElementById('loginBtn').addEventListener('click', function() { 

var ABSOLUTE_URI = "http://mysite123.com/user_home.html"; 
var FB_ID = "12345"; 

    // Open your auth window containing FB auth page 
    // with forward URL to your Opened Window handler page (below) 

    var redirect_uri = "&redirect_uri=" + ABSOLUTE_URI; 
    var scope = "&scope=public_profile,email,user_friends"; 
    var url = "https://www.facebook.com/dialog/oauth?client_id=" + FB_ID + redirect_uri + scope; 

    // notice the lack of other param in window.open 
    // for some reason the opener is set to null 
    // and the opened window can NOT reference it 
    // if params are passed. #Chrome iOS Bug 
    window.open(url); 



function fbCompleteLogin(){ 

Parse.FacebookUtils.logIn(null, { 
    success: function(user) { 
    if (!user.existed()) { 
     alert("User signed up and logged in through Facebook!"); 
    } else { 
     alert("User logged in through Facebook!"); 
    } 
    }, 
    error: function(user, error) { 
    alert("User cancelled the Facebook login or did not fully authorize."); 
    } 
}); 

} 

function requireLogin(callback){ 

    FB.getLoginStatus(function(response) { 
     if (response.status != "connected"){ 
      showLogin(); 
     }else{ 
      checkAuth(response.authResponse.accessToken, response.authResponse.userID, function(success){ 

       // Check FB tokens against your API to make sure user is valid 
      }); 
     } 
    }); 

} 

}, false); 

回答

2

我卡在之前的同一個問題,並解決了它。如果您不想彈出新窗口,請使用OAuth使用Facebook登錄。

可以使用parse-facebook-user-session迅速做到這一點。完成之後,只需使用超鏈接<a>來鏈接登錄頁面。也許你會面對錯誤209無效會話令牌。您應該打開Parse.com儀表板設置頁面上的「需要撤消會話」切換。

如果您仍然有一些問題,如如何檢索用戶的access_token,我在my blog寫了一些帖子,也許它會幫助你(對不起,這些帖子用中文傳統描述)。

UPDATE:

我創建了一個demoGitHub,請檢查。

+0

有無論如何你可以在這裏舉一個很好的例子嗎? – Dano007

+0

我即將入睡(23:48 UTC + 8)。如果明天有空,我會舉一個簡單的例子。 – North

+0

這將是偉大的謝謝;-) – Dano007

1

如果你想自己控制登錄過程,你必須繞過一些分析部分。 我的建議是使用FB api登錄Facebook,您可以自定義。

之後,您將獲得一個來自Facebook的對象,其中包含一些信息,如令牌,過期日期......可以將此對象提供給Parse.FacebookUtils.logIn方法,以便將Facebook帳戶鏈接到解析對象。

這裏是科爾多瓦的一個片段,可能會有一些調整,使。

$cordovaFacebook.getLoginStatus().then(function(rep){ 
    console.log(JSON.stringify(rep)); 
    var expDate = new Date(new Date().getTime() + rep.authResponse.expiresIn * 1000).toISOString(); 
    var authData = { 
    id: String(rep.authResponse.userID), 
    access_token: rep.authResponse.accessToken, 
    expiration_date: expDate 
    } 
    return Parse.FacebookUtils.logIn(authData); 
})