0

Я хочу выполнить три действия.Различные действия согласно состоянию входа в facebook

  1. Если пользователь alread вошел в систему; перенаправить на новую страницу без pageload с помощью ajax
  2. Если вы вошли в систему, но не авторизованы с моим app, тогда сообщите ему, чтобы он сделал
  3. Если не войти в систему, войдите в систему.

Вот моя попытка:

if (response.status === 'connected') { 

    $.ajax({ 
type: "POST", 
url: "url.php", 
success: function(r) 
    { 
    window.location = 'url.php'; // **This ajax code does not work. What is the error?** 
    }, 
}); 

    } else if (response.status === 'not_authorized') { 

//What to do here to ask for subscription with my ID?  

    } else { 

    } 
}); 

Мой реальный код:

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> </head> 
<body style="height: 560px"> 

<div id="fb-root"></div> 
<script type="text/javascript"> 
window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '132292862', // Set YOUR APP ID 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true, // parse XFBML 
     oauth  : true 
    }); 

    FB.Event.subscribe('auth.authResponseChange', function(response) 
    { 
    if (response.status === 'connected') 
     { 
     document.getElementById("log").innerHTML = "You're connected to Facebook <a href='#' onClick='logout()'>log out</a>"; 
     document.getElementById("status").innerHTML='';}  
     else if (response.status === 'not_authorized') 
     { 
     document.getElementById("log").innerHTML = "Connection failed"; 
     } 
     else 
     { 
     document.getElementById("log").innerHTML = "You're logged out"; 
     } 
    }); 
}; 

(function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return; alert('ok');} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 
</script> 
</body> 
</html> 
+1

Что ваш вопрос ?? – asifrc

+0

@asifrc: выполнить 1,2,3 действия! –

ответ

0

попробовать это:

<script> 
window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : 'myId', // Set YOUR APP ID 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true, // parse XFBML 
     oauth  : true 
    }); 

    FB.Event.subscribe('auth.authResponseChange', function(response) 
    { 
    if (response.status === 'connected') 
     { 
     document.getElementById("log").innerHTML = "You're connected to Facebook <a href='#' onClick='logout()'>log out</a>"; 
     document.getElementById("status").innerHTML='';}  
     else if (response.status === 'not_authorized') 
     { 
     document.getElementById("log").innerHTML = "Connection failed"; 
     } 
     else 
     { 
     document.getElementById("log").innerHTML = "You're logged out"; 
     } 
    }); 
}; 

(function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return; alert('ok');} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 
</script> 
+0

спасибо, но id - ошибка null: см. Мой 'обновленный код' –

Смежные вопросы