Вопрос по facebook, jquery, javascript – Определить, зарегистрирован ли пользователь Facebook без всплывающих окон
Я пытаюсь проверить, вошел ли пользователь в 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));
Любая подсказка здесь?
1
ответ
Ты можешь использоватьFB.getLoginStatus
чтобы получить информацию, которую вы хотите.
The first time in the current browser session that
FB.getLoginStatus
is called, or the JS SDK is init'd withstatus: true
, the response object will be cached by the SDK. Subsequent calls toFB.getLoginStatus
will return data from this cached response.
Пример из документации:
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.
}
});