gpt4 book ai didi

javascript - 如果用户已经登录到 FB,如何阻止我的 Facebook 登录弹出窗口出现?

转载 作者:行者123 更新时间:2023-11-30 10:42:28 24 4
gpt4 key购买 nike

我有一个“使用 Facebook 登录”按钮,该按钮会生成一个弹出窗口,要求用户输入 FB 凭据。

如果用户已经加入我的应用程序,离开应用程序然后返回(同时仍登录到 Facebook),我希望用户能够点击“使用 Facebook 登录”而不显示弹出窗口。

目前,鉴于上述段落中的情况,弹出窗口打开一秒钟,然后页面重定向到应用程序的登录状态。

我已经在下面实现了以下代码 - 对于 Javascript,我完全是个菜鸟,所以虽然答案可能很明显,但我不知道该怎么做!

window.fbAsyncInit = function() {
FB.init({
appId : '372191216164729',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};

(function(d) {
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));

$(function() {
$('#fb_connect').click(function(e) {
e.preventDefault();

FB.login(function(response) {
if (response.authResponse) {
// $('#connect').html('Connected! Hitting OmniAuth callback (GET /auth/facebook/callback)...');

//this might not be the best way to do this ...
$('#welcome_form').submit();
// since we have cookies enabled, this request will allow omniauth to parse
// out the auth code from the signed request in the fbsr_XXX cookie
// $.getJSON('/auth/facebook/callback', function(json) {
// $('#connect').html('Connected! Callback complete.');
// $('#results').html(JSON.stringify(json));
// });
}
}, { scope: 'email, read_stream' });
});
});

最佳答案

当页面加载时,加载并初始化 fb sdk 后使用 FB.getLoginStatus 方法来检查用户状态。如果用户已经登录并授权您的应用程序,那么响应应该包含访问 token 、用户 ID 等。

例如:

FB.getLoginStatus(function(response) {
if (response.status === "connected") {
// use the response.authResponse
}
else if (response.status === "not_authorized") {
FB.login(function(response) {
...
}, { scope: "email, read_stream" });
}
else {
// user not logged in to facebook
}
});

关于javascript - 如果用户已经登录到 FB,如何阻止我的 Facebook 登录弹出窗口出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10342041/

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