2011-03-31 208 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

相關問題