Foros del Web » Programando para Internet » PHP »

Loguearse con facebook

Estas en el tema de Loguearse con facebook en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 07/05/2016, 05:02
 
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
  #2 (permalink)  
Antiguo 07/05/2016, 07:19
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Loguearse con facebook

Cita:
pero no se como almacenarlos en variables para utilizarlos en php
Bueno, pues eso es Javascript y debes resolverlo usando únicamente Javascript, no se resuelve con más PHP.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 07/05/2016, 08:13
 
Fecha de Ingreso: octubre-2014
Mensajes: 15
Antigüedad: 9 años, 6 meses
Puntos: 1
Respuesta: Loguearse con facebook

Puedes usar Ajax y mandarlas por POST y hacer las comparaciones en tu script PHP donde tienes las consultas
  #4 (permalink)  
Antiguo 07/05/2016, 09:20
 
Fecha de Ingreso: enero-2010
Ubicación: badajoz
Mensajes: 47
Antigüedad: 14 años, 3 meses
Puntos: 0
Respuesta: Loguearse con facebook

Gracias por contestar, la verdad que no tengo ni idea de ajax, si me puedieras decir como paso la variable que tengo en el script que se llama varemail que esta en este codigo a una variable en php te lo agradeceria.




Código Javascript:
Ver original
  1. function testAPI()
  2.                     {
  3.                         console.log('Welcome!  Fetching your information.... ');
  4.                         FB.api('/me', function(response)
  5.                         {
  6.                        
  7.                             console.log('Successful login for: ' + response.name);
  8.                             document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response.email + '!';
  9.                             varemail = response.email;
  10.                            
  11.                         }
  12.                         );
  13.                     }

Etiquetas: api, facebook, login
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:17.