HTML Code for Facebook Login without Password

 HTML Code for Facebook Login without Password


HTML, JavaScript, Facebook Login, Facebook SDK, App ID, Web Development, Frontend, Authentication, User Login, Social Media Integration


Creating a Facebook login functionality involves integrating the Facebook Login API into your web page. Here's a basic example using HTML and JavaScript. Please note that you'll need to create a Facebook App on the Facebook Developer platform and obtain an App ID to use in the code.



<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Facebook Login Example</title>

</head>

<body>


<div id="fb-root"></div>


<script>

  // Initialize the Facebook SDK

  window.fbAsyncInit = function() {

    FB.init({

      appId      : 'YOUR_APP_ID',

      cookie     : true,

      xfbml      : true,

      version    : 'v14.0'

    });


    // Check login status

    FB.getLoginStatus(function(response) {

      if (response.status === 'connected') {

        // User is logged into Facebook and your app

        console.log('Logged in');

      } else {

        // User is not logged into Facebook or your app

        console.log('Not logged in');

      }

    });

  };


  // Load the SDK asynchronously

  (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'));


  // Function to trigger Facebook login

  function facebookLogin() {

    FB.login(function(response) {

      if (response.authResponse) {

        // User is logged in and granted permissions

        console.log('Successful login');

      } else {

        // User canceled the login or did not grant permissions

        console.log('Login canceled');

      }

    }, { scope: 'public_profile,email' });

  }

</script>


<!-- Your Facebook login button -->

<button onclick="facebookLogin()">Login with Facebook</button>


</body>

</html>


Replace 'YOUR_APP_ID' with the actual App ID obtained from the Facebook Developer platform. Make sure to include the necessary Facebook JavaScript SDK by including the script tag with the SDK URL.


Post a Comment

Previous Post Next Post