Facebook API Exmaple

  • import <script src="jquery.js">
  • Copy in before body section this script


//********************** FB Start***********************
 window.fbAsyncInit = function() {
// alert('fb init');
    FB.init({
      appId      : '778853572132659', // App ID
      channelUrl : 'http://localhost:8080/satyaApp/signin', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    
    
 FB.Event.subscribe('auth.authResponseChange', function(response) 
 {
   if (response.status === 'connected') 
   {
    document.getElementById("message").innerHTML +=  "<br>Connected to Facebook";
    //SUCCESS
    
   }  
 else if (response.status === 'not_authorized') 
    {
     document.getElementById("message").innerHTML +=  "<br>Failed to Connect";

  //FAILED
    } else 
    {
     document.getElementById("message").innerHTML +=  "<br>Logged Out";

     //UNKNOWN ERROR
    }
 }); 

    };
    
    
    
    function fblogin()
 {
  FB.login(function(response) {
     if (response.authResponse) 
     {
       getUserInfo();
     } else 
     {
         console.log('User cancelled login or did not fully authorize.');
      }
   },{scope: 'email,user_photos,user_videos,read_friendlists'});


 }

  function getUserInfo() {   

   FB.api('/me', function(response) {
          var mail = response.email;
          var name = response.name;//picture
          getPhoto();
          
    });
    }
  
 function getPhoto()
 {
   FB.api('/me/picture?type=normal', function(response) {

    var pic =response.data.url;
  
           
    });

 }



  // Load the SDK asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

  //********************** FB END*********************** 

Enter HTML Button Links for Facebook

<a href="#" onclick="fblogin()" class="social"><i class="facebook-square"></i></a>