FacebookOAuth2和PHP/JSDK

FacebookOAuth2和PHP/JSDK,facebook,facebook-javascript-sdk,facebook-php-sdk,Facebook,Facebook Javascript Sdk,Facebook Php Sdk,我已经注册了auth.login,以便对我的服务器进行ajax回调并更新登录计数。它不起作用,因为php sdk坚决拒绝查看用户是否正确登录 JS代码: window.fbAsyncInit = function () { var channelurl='http://'+window.location.hostname+'/channel.html'; FB.init({ appId : window.appid,

我已经注册了auth.login,以便对我的服务器进行ajax回调并更新登录计数。它不起作用,因为php sdk坚决拒绝查看用户是否正确登录

JS代码:

    window.fbAsyncInit = function () {
    var channelurl='http://'+window.location.hostname+'/channel.html';
        FB.init({
            appId : window.appid,
            status: true,
            cookie: true,
            xfbml: true,
            channelURL : channelurl, // channel.html file
            oauth  : true // enable OAuth 2.0
        });
        FB.Event.subscribe('auth.login', function (response) {

                   $("#fbconnecttext").html("<a>Logging in...</v>");

                   $.ajax({
                      url: "fbupdatelogincount",
                      type: "GET",
                      cache: false,
                      success: function (html) {
                          window.setTimeout('$("#fbconnecttext").html("")', 10000);
                          var rec = JSON.parse(html);
                          window.numlogins = rec["numlogins"];
                          FB.api('/me', function (response) {
                             if (window.numlogins > 1) {
                                 $("#fbconnecttext").html(window.welcomebacktext.replace("%s", response.first_name));
                                 $("#fbadminimg").attr("src", "common-images/smiley");
                             }
                             else {
                                 alert(window.firstlogintext.replace("%s", response.first_name));
                             }

                             });

                      }
                      });
               });

        FB.Event.subscribe('auth.logout', function (response) {
                   $("#fbconnecttext").html(window.fbconnecttext);
                   $("#fb-like").show();
                   FB.XFBML.parse($('#fb-like').is());
               });
        FB.Event.subscribe('auth.sessionChange', function (response) {});
    };

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

function fbAuthentication(){

    global $facebook;
    $facebook = new Facebook(array(
                     'appId' => getSetting("fb:app_id"),
                     'secret' => getSetting("fb:secret")
                     ));
    if($facebook->getUser()){
        try {
            global $fb_isadmin,$fb_me;
            $fb_me = $facebook->api('/me');
            $fb_isadmin=strstr(getSetting("fb:admins"),$facebook->getUser())!=false;
            fbUpdateStats();
            return true;
        } catch (FacebookApiException $e) {
            /* exception handling todo */
        }
        return true;
    }else logText("No Valid user");

    return false;

}
主要问题是ajax调用触发了url fbupdatelogincount,但PHP方面说“没有,没有人登录”。有什么想法吗?同样的设置在3.1.1之前运行良好,这似乎没有在任何地方记录,但似乎将应用程序机密传递给auth.login事件会导致它成功触发

试试这个:

FB.Event.subscribe('auth.login', function(response) {
    // callback
}, { secret:'<?php print $facebook->getApiSecret(); ?>' });
FB.Event.subscribe('auth.login',函数(响应){
//回拨
},{秘密:'});

最初的问题已经被Facebook修复。

这似乎没有任何文档记录,但似乎将应用程序机密传递给auth.login事件会导致它成功触发

试试这个:

FB.Event.subscribe('auth.login', function(response) {
    // callback
}, { secret:'<?php print $facebook->getApiSecret(); ?>' });
FB.Event.subscribe('auth.login',函数(响应){
//回拨
},{秘密:'});


最初的问题已经被Facebook解决了。

我终于找到了另一个解决方案:在我的ajax回调中,我添加了accesstoken作为GET参数,在php url对其进行解码,然后调用$Facebook->setAccessToken($at)。现在一切正常。因此,这是新SDK合作中的一个缺陷。多好的一天…;)-

FB.Event.subscribe('auth.authResponseChange',函数(响应){
parse(document.getElementById('FB-like');
if(response.authResponse){
FB.api('/me',函数(响应){
//$(“#fbconnecttext”).html(“”+响应。名字+“”);
});
$.ajax({
url:“fbupdatelogincount?accesstoken=“+response.authResponse.accesstoken,
键入:“获取”,
成功:函数(html){
如果(html){
var rec=JSON.parse(html);
window.numlogins=rec[“numlogins”];
FB.api('/me',函数(响应){
如果(window.numlogins>1){
$(“#fbconnecttext”).html(window.welcomebacktext.replace(“%s”,response.first_name));
$(“#fbadmining”).attr(“src”,“常见图像/笑脸”);
}
否则{
警报(window.firstlogintext.replace(“%s”,response.first_name));
}
});
}
}
});
}否则{
//注销
}
});

我终于找到了另一个解决方案:在ajax回调中,我添加了accesstoken作为GET参数,在php url处对其进行解码,然后调用$facebook->setAccessToken($at)。现在一切正常。因此,这是新SDK合作中的一个缺陷。多好的一天…;)-

FB.Event.subscribe('auth.authResponseChange',函数(响应){
parse(document.getElementById('FB-like');
if(response.authResponse){
FB.api('/me',函数(响应){
//$(“#fbconnecttext”).html(“”+响应。名字+“”);
});
$.ajax({
url:“fbupdatelogincount?accesstoken=“+response.authResponse.accesstoken,
键入:“获取”,
成功:函数(html){
如果(html){
var rec=JSON.parse(html);
window.numlogins=rec[“numlogins”];
FB.api('/me',函数(响应){
如果(window.numlogins>1){
$(“#fbconnecttext”).html(window.welcomebacktext.replace(“%s”,response.first_name));
$(“#fbadmining”).attr(“src”,“常见图像/笑脸”);
}
否则{
警报(window.firstlogintext.replace(“%s”,response.first_name));
}
});
}
}
});
}否则{
//注销
}
});

几个问题:这种未记录的行为究竟修复了什么?其他人如何使用此修复程序?这不是造成了一个巨大的安全漏洞吗?你不会公开透露你的FB AppId和FB AppSecret吗?在Facebook应用程序设置下,在高级选项卡下有一个选项,标记为“要求应用程序机密进行身份验证。登录”,这就是我第一次尝试的想法。当时,这是唯一一个导致auth.login事件触发的修复程序,这样用户的Facebook会话就可以正确加载。目前,该选项似乎已从应用程序设置中删除,而最初的问题已由Facebook修复。这就是使用API的本质,这些API不断地被更改,而没有向开发人员发出太多通知。我在OAuth2.0和Facebook上玩得很开心。强制启动auth.login将是一个很好的解决方案。如果弹出窗口出现但您已登录,则不会触发任何事件。好吧,据我所知。几个问题:这种未记录的行为到底修复了什么?其他人如何使用此修复程序?这不是造成了一个巨大的安全漏洞吗?你不会公开透露你的FB AppId和FB AppSecret吗?在Facebook应用程序设置下,在高级选项卡下有一个选项,标记为“要求应用程序机密进行身份验证。登录”,这就是我第一次尝试的想法。当时,这是唯一一个导致auth.login事件触发的修复程序,这样用户的Facebook会话就可以正确加载。目前,该选项似乎已从应用程序设置中删除,而最初的问题已由Facebook修复。这就是使用API的本质,这些API不断地被更改,而没有向开发人员发出太多通知。我在OAuth2.0和Facebook上玩得很开心。强制启动auth.login将是一个很好的解决方案。路途
FB.Event.subscribe('auth.authResponseChange', function (response) {
    FB.XFBML.parse(document.getElementById('fb-like'));
    if (response.authResponse) {
    FB.api('/me', function(response) {
           // $("#fbconnecttext").html('<a class="fbUserName">'+response.first_name+'</a>');
           });
        $.ajax({
            url: "fbupdatelogincount?accesstoken="+response.authResponse.accessToken,
            type: "GET",
            success: function (html) {
                if (html) {
            var rec = JSON.parse(html);
                    window.numlogins = rec["numlogins"];
                    FB.api('/me', function (response) {
                        if (window.numlogins > 1) {
                            $("#fbconnecttext").html(window.welcomebacktext.replace("%s", response.first_name));
                            $("#fbadminimg").attr("src", "common-images/smiley");
                        }
                        else {
                            alert(window.firstlogintext.replace("%s", response.first_name));
                        }

                    });
                }

            }
        });
    }else{
    //logged out
    }
});