我正在嘗試使用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);
有無論如何你可以在這裏舉一個很好的例子嗎? – Dano007
我即將入睡(23:48 UTC + 8)。如果明天有空,我會舉一個簡單的例子。 – North
這將是偉大的謝謝;-) – Dano007