Conocer si quien visita es Fan de FB, de lo contrario invitarlo


En primer lugar, como ya he explicado en post anteriores, debemos crear una aplicación sencilla donde le pidamos el permiso para acceder a sus datos de fb. Nada del otro mundo.
Luego,con el siguiente codigo, podemos saber si quien nos visita, le ha dado clicks a nuestro fan page en FB : 
todo el siguiente codigo debe ser invocado desde otro lugar, en este caso usaremos un iframe que llame a todo este html, por ejemplo : wwwmidominio.com/esfan.html y lo llamaremos asi:

<iframe scrolling="no" style="border:none; overflow:hidden; width:400px; height:200px;" src="wwwmidominio.com/esfan.html"></iframe>


y wwwmidominio.com/esfan.html  vendria a ser todo lo siguiente :


<html>
<head>

<style>


.box_img-background {
  background: #DDDDDD ;
  width: 460px !important;
  height: 200px;
  float: left;
  position: relative;
}
.box_img-background .box_rs {
  position: absolute;
  left: 50px;
  top: 25px;
}

.box_img-fan {
  background: black url(http://ranking2013.studio92.com/tmp/img/img-esfan.jpg) no-repeat 0 0;
  width: 460px !important;
  height: 200px;
  float: left;
  position: relative;
}
.box_img-fan .box_rs {
  position: absolute;
  left: 50px;
  top: 25px;
}

</style>

//**CAMBIAR CON EL LINK DE TU FAN PAGE**//

</HEAD>
<body>
  <div id="iframee" class="box_img-background"  style="display:none; padding: 15px;">
  <div class="fb-like-box" data-href="https://www.facebook.com/ [TU PAGINA FB] " data-width="400" data-show-faces="false" data-stream="false" data-header="false"></div>
  </div>
  <div id="sifan" class="box_img-fan" style="display:none; padding: 15px;"> ya eres fan! </div>
<div id="fb-root"></div>
<script>

 
  window.fbAsyncInit = function(){
   
  FB.init({
    appId      : '121212121212121', //** App ID DE TU APLICACION QUE DA PERMISOS **//
    channelUrl : 'www.midominio.channel', //** aqui colocar url que ya conpartire mas adelante**//
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });

  FB.Event.subscribe('edge.create', function(response) {
     /*  $.post("common/securimage/likes.php", {id: userObject.userid,voto:1,fb:userObject.username},
        function(rest){
            if(rest){
                $('#likebutton').show();
                $('#fade_1').show();
            }
           
            else{
              alert('se produjo un error de conexion, por favor, intentarlo nuevamente. ');
              window.location='index.php';
            }
        });*/
  document.location.href = document.location.href;
 });
  // Additional initialization code here
 
  FB.Canvas.setSize({ width:810, height:680});

  init();

  function init(){

    FB.getLoginStatus(function(response) {
      FB.api('me/likes/175008385878292',function(response) {
     
          if(response.data) {
              if( !isEmpty(response.data) ){
                 document.getElementById("sifan").style.display="block";
              }else{
                document.getElementById("iframee").style.display="block";
              }
                 
          }else{
              document.getElementById("iframee").style.display="block";
          }
      });
   
    });

   


    };

  }

function isEmpty(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }

    return true;
}

  // 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));
</script>

</body>
</html>

para finalizar :

www.midominio.channel teiene solo este codigo : 

<script src="//connect.facebook.net/en_US/all.js"></script>



No hay comentarios:

Publicar un comentario

Todos los comentarios son bien recibidos...

CommentFB