Explorar el Código

FB登入測試

Mike hace 3 años
padre
commit
1b0617f76d
Se han modificado 1 ficheros con 67 adiciones y 38 borrados
  1. 67 38
      desktop11/index.html

+ 67 - 38
desktop11/index.html

@@ -29,6 +29,65 @@
 </head>
 </head>
 
 
 <body id="top">
 <body id="top">
+<script>
+function statusChangeCallback(response) {  // Called with the results from FB.getLoginStatus().
+    console.log('statusChangeCallback');
+    console.log(response);                   // The current login status of the person.
+    if (response.status === 'connected') {   // Logged into your webpage and Facebook.
+        testAPI();  
+    } else {                                 // Not logged into your webpage or we are unable to tell.
+        // document.getElementById('status').innerHTML = 'Please log ' +
+        // 'into this webpage.';
+        $('#status').html('FB登入按扭(開發中),請勿點擊');
+    }
+}
+
+function checkLoginState() {               // Called when a person is finished with the Login Button.
+    FB.getLoginStatus(function(response) {   // See the onlogin handler
+        console.log(statusChangeCallback(response));
+    });
+}
+
+window.fbAsyncInit = function() {
+    FB.init({
+        appId      : '1388696554848391',
+        cookie     : true,            // Enable cookies to allow the server to access the session.
+        xfbml      : true,            // Parse social plugins on this webpage.
+        version    : 'v11.0'           // Use this Graph API version for this call.
+    });
+
+    FB.getLoginStatus(function(response) {   // Called after the JS SDK has been initialized.
+        statusChangeCallback(response);        // Returns the login status.
+    });
+};
+
+function testAPI() {                      // Testing Graph API after login.  See statusChangeCallback() for when this call is made.
+    console.log('Welcome!  Fetching your information.... ');
+    FB.api('/me', function(response) {
+    console.log('Successful login for: ' + response.name);
+    document.getElementById('status').innerHTML =
+        'Thanks for logging in, ' + response.name + '!';
+    });
+}
+
+testAPI();
+
+function callFB() {
+    FB.login(function(response) {
+        if (response.authResponse) {
+            console.log('Welcome!  Fetching your information.... ');
+            FB.api('/me', function(response) {
+                console.log('Good to see you, ' + response.name + '.');
+            });
+        } else {
+            console.log('User cancelled login or did not fully authorize.');
+        }
+    });
+}
+
+callFB();
+</script>
+
     <div class="container-fluid" style="padding:0;margin:0 ">
     <div class="container-fluid" style="padding:0;margin:0 ">
         <div class="banner container-fluid" style="padding:0; margin:0 ">
         <div class="banner container-fluid" style="padding:0; margin:0 ">
             <!-- <section id="banner"> -->
             <!-- <section id="banner"> -->
@@ -362,10 +421,14 @@
                         </div>
                         </div>
                         <hr>
                         <hr>
                         <div id="form-right">
                         <div id="form-right">
-                            <div id="facebook" onclick='callFB()'>
+                            <!-- <div id="facebook" onclick='callFB()'>
                                 <img src="./img/logo/facebook.webp" alt="">
                                 <img src="./img/logo/facebook.webp" alt="">
                                 使用FB填入信箱與姓名
                                 使用FB填入信箱與姓名
-                            </div>
+                            </div> -->
+                            
+                            <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">使用FB填入信箱與姓名</fb:login-button>
+                            <div id="status"></div>
+                            
                             <input type="text" name="email" id="email" placeholder="請輸入信箱" required>
                             <input type="text" name="email" id="email" placeholder="請輸入信箱" required>
                             <input type="text" name="name" id="name" placeholder="請輸入姓名" required>
                             <input type="text" name="name" id="name" placeholder="請輸入姓名" required>
                             <input type="text" name="phone" id="phone" placeholder="請輸入電話" required>
                             <input type="text" name="phone" id="phone" placeholder="請輸入電話" required>
@@ -397,42 +460,8 @@
         </div>
         </div>
     </div>
     </div>
 
 
-
-
-
-
-
-
-
-
-<!-- <script>
-window.fbAsyncInit = function() {
-    FB.init({
-    appId      : '582473075602626',
-    cookie     : true,
-    xfbml      : true,
-    version    : '{api-version}'
-    });
-    
-    FB.AppEvents.logPageView();   
-    
-};
-
-(function(d, s, id){
-    var js, fjs = d.getElementsByTagName(s)[0];
-    if (d.getElementById(id)) {return;}
-    js = d.createElement(s); js.id = id;
-    js.src = "https://connect.facebook.net/en_US/sdk.js";
-    fjs.parentNode.insertBefore(js, fjs);
-}(document, 'script', 'facebook-jssdk'));
-
-FB.getLoginStatus(function(response) {
-    statusChangeCallback(response);
-});
-</script> -->
-
-
-
+    <!-- Load the JS SDK asynchronously -->
+    <script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js"></script>
 
 
     <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
     <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
         integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
         integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"