2011-04-12 71 views
0

我想让用户使用他们的Facebook帐户登录到我的网站。我曾尝试从Facebook开发者页面(http://developers.facebook.com/docs/)阅读与该过程相关的一些信息 - 虽然过程和逻辑类型有意义,但我仍然忽略了大局。Facebook连接的网站 - 数据库连接和逻辑

'Facebook连接'如何链接到我现有的用户及其属性数据库。假设有一个叫John Walker的用户,他是一个注册用户(登录名:jwalker pass:1234账户余额:10美元)。当他来到网站,并尝试使用Facebook登录进行登录时,该如何知道在哪里指导他?换句话说,Facebook如何知道它是正确的John Walker,并且他应该被发送到他的用户页面?

如果这个问题微不足道,我很抱歉,但我不能认为这是我自己。感谢您的帮助!

扎卡里

回答

0

好扎卡里,您对Facebook的连接有点误解。当用户点击放置在您网站上的Facebook连接按钮时,Facebook不会访问您的数据库来验证用户身份。他在他的数据库中验证用户是否当前用户有Facebook帐户...如果他/她有帐户,那么Facebook通过将他登录到Facebook来为该特定用户颁发访问令牌。那么现在您有责任在系统中登录该用户,并将他的信息放入您的数据库。让我进一步解释并看看下面的代码

 
<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({appId: "Your APP ID", 
      status: true, 
      cookie: true, 
      xfbml: true}); 

    FB.getLoginStatus(function(response) { 
     if (response.session) { 
     // This is the place where you get control when user is login to facebook 
       // At this point you can redirect the user to a page where you can put the facebook returned information to database and login him into your system 

     } else { 

     } 
    }); 
    FB.Event.subscribe("auth.login", function(response) { 

    window.location.reload(); 
     }); 
FB.Event.subscribe("auth.logout", function(response) { 


    self.location.href="http://www.iranibash.com/logout.php"; 
     }); 
    }; 
    (function() { 
    var e = document.createElement("script"); 
    e.src = document.location.protocol + "//connect.facebook.net/en_US/all.js"; 
    e.async = true; 
    document.getElementById("fb-root").appendChild(e); 
    }()); 
    </script> 

现在您可以使用Facebook成功登录后返回您的用户信息。您可以在$ cookie中获得该信息。我认为你可以从这些信息中了解吗?