Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/05/2016, 05:02
ma_miranda19
 
Fecha de Ingreso: enero-2010
Ubicación: badajoz
Mensajes: 47
Antigüedad: 14 años, 3 meses
Puntos: 0
Exclamación Loguearse con facebook

Buenos dias, llevo toda la semana intentando poner un login de facebook para entrar en mi web, me aparece el boton y consigo que me muestre en pantalla en nombre con el que estoy logueado y el email pero no consigo pasarlo a una variable para utilizarlo al buscar en la base de datos, este es el script que tengo en <head>:


Código Javascript:
Ver original
  1. <script>(function(d, s, id) {
  2.   var js, fjs = d.getElementsByTagName(s)[0];
  3.   if (d.getElementById(id)) return;
  4.   js = d.createElement(s); js.id = id;
  5.   js.src = "//connect.facebook.net/es_LA/sdk.js#xfbml=1&version=v2.6&appId=xxxxxxxxxxxxxxxxx";
  6.   fjs.parentNode.insertBefore(js, fjs);
  7. }(document, 'script', 'facebook-jssdk'));</script>




Código Javascript:
Ver original
  1. <script>
  2.   // This is called with the results from from FB.getLoginStatus().
  3.   function statusChangeCallback(response) {
  4.     console.log('statusChangeCallback');
  5.     console.log(response);
  6.     // The response object is returned with a status field that lets the
  7.     // app know the current login status of the person.
  8.     // Full docs on the response object can be found in the documentation
  9.     // for FB.getLoginStatus().
  10.     if (response.status === 'connected') {
  11.       // Logged into your app and Facebook.
  12.       testAPI();
  13.     } else if (response.status === 'not_authorized') {
  14.       // The person is logged into Facebook, but not your app.
  15.       document.getElementById('status').innerHTML = 'Por favor logeese en ' +
  16.         'into this app.';
  17.     } else {
  18.       // The person is not logged into Facebook, so we're not sure if
  19.       // they are logged into this app or not.
  20.       document.getElementById('status').innerHTML = 'Por favor logeese en ' +
  21.         'Facebook.';
  22.     }
  23.   }
  24.  
  25.   // This function is called when someone finishes with the Login
  26.   // Button.  See the onlogin handler attached to it in the sample
  27.   // code below.
  28.   function checkLoginState() {
  29.     FB.getLoginStatus(function(response) {
  30.       statusChangeCallback(response);
  31.     });
  32.   }
  33.  
  34.   window.fbAsyncInit = function() {
  35.   FB.init({
  36.     appId      : '{990754610948208}',
  37.     cookie     : true,  // enable cookies to allow the server to access
  38.                         // the session
  39.     xfbml      : true,  // parse social plugins on this page
  40.     version    : 'v2.2' // use version 2.2
  41.   });
  42.  
  43.   // Now that we've initialized the JavaScript SDK, we call
  44.   // FB.getLoginStatus().  This function gets the state of the
  45.   // person visiting this page and can return one of three states to
  46.   // the callback you provide.  They can be:
  47.   //
  48.   // 1. Logged into your app ('connected')
  49.   // 2. Logged into Facebook, but not your app ('not_authorized')
  50.   // 3. Not logged into Facebook and can't tell if they are logged into
  51.   //    your app or not.
  52.   //
  53.   // These three cases are handled in the callback function.
  54.  
  55.   FB.getLoginStatus(function(response) {
  56.     statusChangeCallback(response);
  57.   });
  58.  
  59.   };
  60.  
  61.   // Load the SDK asynchronously
  62.   (function(d, s, id) {
  63.     var js, fjs = d.getElementsByTagName(s)[0];
  64.     if (d.getElementById(id)) return;
  65.     js = d.createElement(s); js.id = id;
  66.     js.src = "//connect.facebook.net/en_US/sdk.js";
  67.     fjs.parentNode.insertBefore(js, fjs);
  68.   }(document, 'script', 'facebook-jssdk'));
  69.  
  70.   // Here we run a very simple test of the Graph API after login is
  71.   // successful.  See statusChangeCallback() for when this call is made.
  72.   function testAPI()
  73.                     {
  74.                         console.log('Welcome!  Fetching your information.... ');
  75.                         FB.api('/me', function(response)
  76.                         {
  77.                        
  78.                             console.log('Successful login for: ' + response.name);
  79.                             document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response.email + '!';
  80.                         }
  81.                         );
  82.                     }
  83.                    
  84. </script>

//////
He locacalizado que response.email mi muestra el correo y si cambio a response.name me saca el nombre, pero no se como almacenarlos en variables para utilizarlos en php, mas abajo tengo el boton con el codigo:

Código HTML:
Ver original
  1. <div id="status">
  2. </div>
  3. <div class="fb-login-button" data-max-rows="1" data-size="medium" data-show-faces="false" data-auto-logout-link="false"></div>


Espero que me puedan ayudar, muchas gracias.

Última edición por ma_miranda19; 07/05/2016 a las 05:15