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 討論區載入中...