dpgui8229808 2013-05-27 22:06
浏览 38
已采纳

关于FB.Event.subscribe和FB.login

first thanks for your time. Im trying to build a Event for facebook login button, to redirect to a PHP that always insert the user in db, if already exists just update some stuff..

The problem is this following this steps

  1. My status is loged out from facebook & site.. i use facebook login button to login, it ask for my facebook credentials, if i login, it redirect me to index.php?fbconnect=fbconnect wich is great, and im Perfectly Logged In , in facebook & in my site!!

  2. If i logout, everything its fine ....i am just loged out from my site, not from facebook

  3. If im connected to facebook , but not to my site, and click "login with facebook", NO redirection happends, so the user never logins, :( WHY?

I have tried this 3 different methods to redirect but all of them just work as i mention before.

This is a solution im trying to fix the issue i comment here, if i got this redirection everything would be perfect. but its a shame it only work the first time

   <script>
 window.fbAsyncInit = function() {
 FB.init({
 appId : <?=YOUR_APP_ID?>,
 status : true,
 cookie : true,
 xfbml : true,
 oauth : true,
 });



FB.Event.subscribe('auth.login', function(response) {
 // ------------------------------------------------------
 // This is the callback if everything is ok
 window.location.href = 'http://www.page.com.mx/index.php?fbconnect=fbconnect';

 });


 FB.Event.subscribe('edge.create', function(response) {
  window.location.href = 'http://www.page.com.mx/index.php?fbconnect=fbconnect';
});

 FB.login(function(response) {window.location.href = 'http://www.page.com.mx/index.php?fbconnect=fbconnect';
              //...
           });
          };


(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));
</script>
  • 写回答

1条回答 默认 最新

  • dpj96988 2013-05-30 21:25
    关注

    Assuming that we have 3 possible status when asking the fb.getloginstatus (connected, not_authorized, not 'connected' nor 'not_authorized'), I tested this solution in my app only for the first and the third status, this because in my app, when I logout, I'm logged out from facebook to. Anyway I get all this stuff from the facebook documentation. I don't know if I understand right but the events you are searching for, the one which is fired by the login, is: 'auth.login' it's all written in the facebook docs.

    So, if you want to redirect the user, just, and only after he is logged in, you should handle the things in this way:

    FB.Event.subscribe('auth.login',
        function(response) {
            alert('you just login, come with me');
            //redirect
        }
    );
    

    I put this code in this function window.fbAsyncInit = function() { , just before to handle FB.Event.subscribe('auth.authResponseChange', function(response) { but probably it's better to handle the auth.authResponseChange before the auth.login.

    for last I would like to add that there are also other ways to collect user data once for each session

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用