2011-03-31 225 views
1

我在我的网站上有我的登录按钮,这一切都正常。但我想获得用户的电子邮件,名字和姓氏和Facebook的ID,并将它们存储在数据库中,一旦我得到了详细信息,我知道如何将它们添加到数据库,它只是从Facebook获取信息,这是我的问题权限访问有基本信息和发送电子邮件我只是想知道我是如何获得这些信息在用户登录Facebook后获取用户详细信息

我的登录按钮看起来像这样

script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
      FB.init({ 
      appId:'137558232981530', cookie:true, 
      status:true, xfbml:true 
     }); 
     $num = 1; 
     </script> 
     <fb:login-button perms="email, user_about_me, publish_stream">Login with Facebook</fb:login-button> 
+0

所以你想获得这些信息,没有任何用户的预先许可?我真的不认为这会起作用,如果是这样,那么fb应该做一些事情!因为据我所知,如果任何FB APP想要使用任何个人信息,我必须给予我的许可。 – ITroubs 2011-03-31 17:18:38

+0

没有他们给予的许可 – James 2011-04-01 08:34:09

回答

0

当它被调用,您可以订阅fb-login-button代码引发的事件。试试这个:

<html> 
<head> 
</head> 
<body> 

<fb:login-button perms="email,user_about_me,publish_stream"></fb:login-button> 

<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
    FB.init({ 
     appId:'137558232981530', 
     cookie:true, 
     status:true, 
     xfbml:true 
    }); 

    FB.Event.subscribe('auth.login', function(response) 
    { 
     // handle the response however you want, response should be a session with user info 
     // that you can POST to a server-side script and extract whatever data you need. 
    }); 
</script> 
</body> 
</html> 
+0

我会如何将facebookID分配给我可以发布的变量? – James 2011-04-01 09:46:48

+0

我忘记了什么回应(在您最喜欢的Javascript调试控制台中的'console.debug(response)'应该可以帮助您学习),但我认为它就像是response.session.uid。所以你会做'$ .post('/你/你想要/发送',{uid:response.session.uid},函数(ajax_response){//继续});'在那个FB里面.Event回调。一旦你有了这些数据,你就不需要使用Facebook方法来存储它,只需使用jQuery或查询字符串参数或任何你喜欢的东西。 – 2011-04-01 13:59:50

相关问题