JAVASCRIPT 86
Facebook.js Guest on 14th April 2021 01:13:08 AM
  1. function statusChangeCallback(response) {
  2.       ///console.log(response);
  3.       // The response object is returned with a status field that lets the
  4.       // app know the current login status of the person.
  5.       // Full docs on the response object can be found in the documentation
  6.       // for FB.getLoginStatus().
  7.       if (response.status === 'connected') {
  8.             // Logged into your app and Facebook.
  9.             getFacebookProfile();
  10.       } else if (response.status === 'not_authorized') {
  11.             // The person is logged into Facebook, but not your app.
  12.             console.log('Please log ' +'into this app.');
  13.       } else {
  14.             // The person is not logged into Facebook, so we're not sure if
  15.             // they are logged into this app or not.
  16.             console.log('Please log ' +'into Facebook.');
  17.       }
  18. }
  19.  
  20. // This function is called when someone finishes with the Login
  21. // Button.  See the onlogin handler attached to it in the sample
  22. // code below.
  23. function checkLoginState() {
  24.       FB.getLoginStatus(function(response) {
  25.         statusChangeCallback(response);
  26.       });
  27. }
  28.  
  29. window.fbAsyncInit = function() {
  30.       FB.init({
  31.             appId      : GB.fb_appid,//1004859066232454
  32.             cookie     : true,  // enable cookies to allow the server to access
  33.                                     // the session
  34.             xfbml      : true,  // parse social plugins on this page
  35.             version    : 'v2.2' // use version 2.2
  36.       });
  37.  
  38.       // Now that we've initialized the JavaScript SDK, we call
  39.       // FB.getLoginStatus().  This function gets the state of the
  40.       // person visiting this page and can return one of three states to
  41.       // the callback you provide.  They can be:
  42.       //
  43.       // 1. Logged into your app ('connected')
  44.       // 2. Logged into Facebook, but not your app ('not_authorized')
  45.       // 3. Not logged into Facebook and can't tell if they are logged into
  46.       //    your app or not.
  47.       //
  48.       // These three cases are handled in the callback function.
  49.  
  50.       FB.getLoginStatus(function(response) {
  51.             statusChangeCallback(response);
  52.       });
  53.  
  54. };
  55.  
  56. // Load the SDK asynchronously
  57. (function(d, s, id) {
  58.       var js, fjs = d.getElementsByTagName(s)[0];
  59.       if (d.getElementById(id)) return;
  60.       js = d.createElement(s); js.id = id;
  61.       js.src = "//connect.facebook.net/en_US/sdk.js";
  62.       fjs.parentNode.insertBefore(js, fjs);
  63. }(document, 'script', 'facebook-jssdk'));
  64.  
  65. // Here we run a very simple test of the Graph API after login is
  66. // successful.  See statusChangeCallback() for when this call is made.
  67. function getFacebookProfile() {
  68.       var fbData;
  69.       try{
  70.             FB.api('/me', function(response) {
  71.                   fbData=response;
  72.                   console.log(response);
  73.                   console.log('Successful login for: ' + response.name);
  74.             });
  75.       }catch(errMsg){
  76.             console.log('Error: '+errMsg);
  77.       }
  78.       return fbData;
  79. }
  80.  
  81.  
  82. function loginWithFb()
  83. {
  84.       try{
  85.             FB.getLoginStatus(function(response) {
  86.                   if (response.status === 'connected') {
  87.                         /*var fbData=getFacebookProfile();
  88.                         console.log(fbData);
  89.                         */
  90.                         FB.api('/me', function(response) {
  91.                               var ok=getAjax("GET",GB.base_url+"/modules/member/index.php", "actions=login&mode=facebook&id="+response.id+'&'+$('#frmLogin').serialize(),'',"html",false,"load.gif");
  92.                               if(ok==true){
  93.                                     location.href=GB.base_url+'/';
  94.                               }else{
  95.                                     alert(LANGJS['member_account_no_config_facebook']);
  96.                               }
  97.                         });
  98.                   }else{
  99.                         FB.login(function(response)
  100.                         {
  101.                               console.log(response);
  102.                               if (response.authResponse)
  103.                               {
  104.                                     getFacebookProfile();
  105.                               }
  106.                         },
  107.                         {scope: 'public_profile,email,user_likes',return_scopes: true},
  108.                         {cb:checkLoginState()}
  109.                         );
  110.                   }
  111.             });
  112.       }catch(errMsg){
  113.             console.log('Error: '+errMsg);
  114.       }
  115. }
  116.  
  117. function logoutWithFb(){
  118.       try{
  119.             FB.logout(function(response) {
  120.                   // handle the response
  121.                   console.log('loginWithFb: ');
  122.                   console.log(response);
  123.             });
  124.       }catch(errMsg){
  125.             console.log('Error: '+errMsg);
  126.       }
  127. }

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.