且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Facebook OAuth2.0实现

更新时间:2023-02-16 15:55:43

这个问题真的没有解释太多,但猜测一点点,这样做应该做(我不熟悉旧的api,所以我不知道你是否必须传递任何参数update_user_is_connected / not_connected,相应地修改):

  window.fbAsyncInit = function(){
FB.init({
appId:'<%= ConfigurationManager.AppSettings [ ApiKey]。ToString()%>',
status:true,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml :true,// parse XFBML
channelUrl:'http://www.yourdomain.com/channel.html',//自定义渠道网址
oauth:true //启用OAuth 2.0
});

FB.getLoginStatus(function(response){
if(response.authResponse)update_user_is_connected();
else update_user_is_not_connected();
});

//一旦用户登录到Facebook(通过您的站点)
FB.Event.subscribe('auth.login',function(response){
update_user_is_connected();
});
};

您可以阅读更多信息:



http://developers.facebook.com/docs/reference/javascript/FB。 getLoginStatus /


I am new to Facebook implementation . Please help me to implement this code through new all.js using OAuth2.0

 window.addEvent('domready', function(){     
 FB.init("<%= ConfigurationManager.AppSettings["ApiKey"].ToString() %>", 
         "/xd_receiver.htm",
         {"ifUserConnected": update_user_is_connected,
          "ifUserNotConnected": update_user_is_not_connected,
          "doNotUseCachedConnectState":"true"});
});

The question doesn't really explain much, but guessing a little bit, something like this should do (I'm not familiar with the old api, so I don't know whether you have to pass any arguments to update_user_is_connected/not_connected, modify that accordingly):

window.fbAsyncInit = function() {
    FB.init({
        appId  : '<%= ConfigurationManager.AppSettings["ApiKey"].ToString() %>',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true,  // parse XFBML
        channelUrl  : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
        oauth : true //enables OAuth 2.0
    });

    FB.getLoginStatus(function(response) {
        if (response.authResponse) update_user_is_connected();
        else update_user_is_not_connected();
    });

    // This will be triggered as soon as the user logs into Facebook (through your site)
    FB.Event.subscribe('auth.login', function(response) {
        update_user_is_connected();
    });
};

You can read more at:

http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/