0

我已爲我的網站添加了Facebook登錄按鈕。代碼給出波紋管,如何訪問Facebook中重定向頁面中的用戶數據

<html> 
<head> 
<title>My Great Web page</title> 
</head> 
<body> 

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

     }; 

     (function(d){ 
      var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      d.getElementsByTagName('head')[0].appendChild(js); 
     }(document)); 
     </script> 

<div class="fb-login-button" data-show-faces="false" data-width="200" data-max-rows="1" scope="user_about_me,user_activities,user_birthday,email" on-login="top.location = 'http://localhost/index.php/';">Login with Facebook</div> 

</body> 
</html> 

當用戶點擊按鈕「用Facebook登錄」,則顯示擴展權限驗證窗口。當用戶允許訪問的細節,用戶使用

on-login="top.location = 'http://localhost/index.php/';" 

現在我想打印所有允許訪問的詳細信息,如用戶名,生日等定向到index.php文件。在index.php文件
任何人都可以請告訴我該怎麼做?

+0

你爲什麼重定向登錄後的用戶?這有什麼特別的理由嗎? – 2012-03-20 08:00:13

+0

原因是我需要將用戶的所有細節都分配到單獨的頁面。總之要做到這一點? – Roshanck 2012-03-20 08:06:17

+0

至少有沒有辦法讓細節到同一頁? – Roshanck 2012-03-20 08:14:41

回答

1

我不知道你在哪裏得到這個登錄屬性的登錄按鈕(我找不到它),但這裏是一個如何做你想做的例子。 它沒有經過測試,我只是爲了明白這一點而創建的。

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

    FB.Event.subscribe("auth.login", function (response) { 
     if (response.status == "connected") { 
      var userid = response.authResponse.userID; 
      var signedRequest = response.authResponse.signedRequest; 
      var expiresIn = response.authResponse.expiresIn; 
      var accessToken = response.authResponse.accessToken; 

      // do something with the data. 

      window.location = "index.php"; 
     } 
    }); 

    (function(d){ 
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     d.getElementsByTagName('head')[0].appendChild(js); 
    }(document)); 
</script> 

<div class="fb-login-button" data-show-faces="false" data-width="200" data-max-rows="1" scope="user_about_me,user_activities,user_birthday,email">Login with Facebook</div> 

你可以閱讀更多有關訂閱事件在這裏:FB.Event.subscribe,並且此線程可能對您有用:Get user basic information using facebook Login button plugin?

相關問題