gpt4 book ai didi

javascript - Parse.FacebookUtils.logIn 是否只允许通过弹出框登录 Facebook?

转载 作者:行者123 更新时间:2023-11-29 10:39:36 24 4
gpt4 key购买 nike

我正在尝试使用 parse.com Facebook SDK 让我的用户使用 Facebook 登录按钮登录到我的网站。

我在桌面浏览器和 Safari 上运行良好,但 ios Chrome 存在一个已知问题,该问题会导致所讨论的错误 here .

我的调查使我得出结论,是 Parse.FacebookUtils.logIn 类导致 Facebook 弹出窗口打开,对吗?

如果是这样,是否可以将其作为页面而不是弹出窗口打开?这将避免上述错误。

我已经构建了一个适用于标准 Facebook 登录但不适用于 Parse 的解决方法。不确定是否可以使用它?此解决方法的信息来自 here .

我也看到了 Rahul 的回答 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);

最佳答案

我之前卡在同一个问题上,解决了。如果您不想弹出新窗口,请使用 OAuth 登录 facebook。

您可以使用 parse-facebook-user-session快速完成。完成后,只需使用超链接 链接登录页面即可。也许您会遇到错误 209 invalid session token。您应该只打开 Parse.com 仪表板设置页面上的“需要可撤销 session ”开关。

如果你还有一些问题比如如何获取用户的access_token,我在my blog写了一些帖子也许它会对你有所帮助(抱歉,这些帖子是用繁体中文描述的)。

更新:

我创建了一个 demoGitHub ,请检查。

关于javascript - Parse.FacebookUtils.logIn 是否只允许通过弹出框登录 Facebook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31500249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com