[英]Detect if facebook user is logged in with no popups
我正在嘗試檢查用戶是否已登錄Facebook(並重定向到其他頁面),但是無法為此打開任何彈出窗口:
這將起作用:但是如果用戶未登錄Facebook,則會打開一個彈出窗口
FB.login(function(response) {
if(response.status == 'connected')
/*Redirect here*/
});
這是在我的另一個網絡中工作的,但不在這里
window.fbAsyncInit = function() {
FB.init({
appId : myAppid, // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.login', function() {
/* REDIRECT HERE */
});
};
// Load the SDK Asynchronously
(function(d){
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/es_ES/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
這里有什么線索嗎?
您可以使用FB.getLoginStatus
獲取所需的信息。
在當前瀏覽器會話中,第一次調用
FB.getLoginStatus
或以status: true
初始化JS SDK時,響應對象將被SDK緩存。 隨后調用FB.getLoginStatus
將從此緩存的響應中返回數據。
文檔中的示例:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.