判斷 Facebook Login User
  • 3,452 views,
  • 2013-09-18,
  • 上傳者: Kuann Hung,
  •  0
67a35e63003675f6b0446cbb828de783.jpg
這是 FB Developer Blog 在 2012/5/8 發表的。用來判斷當 User 已經登入 FB 的判斷,先註記起來,以後一定用得上的!
 
<!DOCTYPE html>
 
<html>
  <head>
    <title>Example</title>
  </head>
  <body>
    <!-- Load the Facebook JavaScript SDK -->
    <div id="fb-root"></div>
    <script src="//connect.facebook.net/en_US/all.js"></script>
     
    <script type="text/javascript">
       
      // Initialize the Facebook JavaScript SDK
      FB.init({
        appId: 'APP_ID',
        xfbml: true,
        status: true,
        cookie: true,
      });
       
      // Check if the current user is logged in and has authorized the app
      FB.getLoginStatus(checkLoginStatus);
       
      // Login in the current user via Facebook and ask for email permission
      function authUser() {
        FB.login(checkLoginStatus, {scope:'email'});
      }
       
      // Check the result of the user status and display login button if necessary
      function checkLoginStatus(response) {
        if(response && response.status == 'connected') {
          alert('User is authorized');
           
          // Hide the login button
          document.getElementById('loginButton').style.display = 'none';
           
          // Now Personalize the User Experience
          console.log(‘Access Token: ‘ + response.authResponse.accessToken);
        } else {
          alert('User is not authorized');
           
          // Display the login button
          document.getElementById('loginButton').style.display = 'block';
        }
      }
    </script>
     
    <input id="loginButton" type="button" value="Login!" onclick="authUser();" />
  </body>
</html>
Facebook 討論區載入中...
資料夾 :
標籤 :
發表時間 :
2013-09-18 20:45:15
觀看數 :
3,452
發表人 :
Kuann Hung
部門 :
老洪的 IT 學習系統
QR Code :