从PHP使用FaceBook API登录无法正常工作

时间:2018-07-25 01:08:52

标签: javascript php facebook-javascript-sdk facebook-php-sdk

我正在尝试从我的网络登录或向Facebook注册,但没有用,实际上是几周后才恢复工作,但是自上周以来,它没有更改API的状态< / p>

在父文件中(给它起个名字)bucause我在MVC中使用PHP,我这样声明脚本

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '300012410734892',
      cookie     : true,
      xfbml      : true,
      version    : 'v3.0'
    });

    FB.AppEvents.logPageView();   

  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "https://connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

并且在我将数据发送到控制器的JS文件中,我完成了所有这些操作

/*=============================================
FACEBOOK Button
=============================================*/

$(".facebook").click(function(){

    FB.login(function(response){

        validateUser();

    }, {scope: 'public_profile, email'})

})

/*=============================================
Validate the login
=============================================*/

function validateUser(){

    FB.getLoginStatus(function(response){

        statusChangeCallback(response);

    })

}

/*=============================================
VALIDATE THE CHANG OF STATUS IN FACEBOOK
=============================================*/

function statusChangeCallback(response){

    if(response.status === 'connected'){

        testApi();

    }else{
        console.log("response", response);
        swal({
          title: "¡ERROR!",
          text: "¡There was an error logging in with Facebook, try again!",
          type: "error",
          confirmButtonText: "Close",
          closeOnConfirm: false
        },

        function(isConfirm){
            if (isConfirm) {    
                window.location = localStorage.getItem("rutaActual");
            } 
        });

    }

}

/*=============================================
API FACEBOOK
=============================================*/

function testApi(){

    FB.api('/me?fields=id,name,email,picture',function(response){

        if(response.email == null){

            swal({
              title: "¡ERROR!",
              text: "¡To enter the system you must provide the email information!",
              type: "error",
              confirmButtonText: "Close",
              closeOnConfirm: false
            },

            function(isConfirm){
                if (isConfirm) {    
                    window.location = localStorage.getItem("rutaActual");
                } 
            });

        }else{

            var email = response.email;
            var name= response.name;
            var picture= "http://graph.facebook.com/"+response.id+"/picture?type=large";

            var datos = new FormData();
            datos.append("email", email);
            datos.append("name",name);
            datos.append("picture",picture);

            $.ajax({

                url:rutaOculta+"ajax/usuarios.ajax.php",
                method:"POST",
                data:datos,
                cache:false,
                contentType:false,
                processData:false,
                success:function(respuesta){

                    if(respuesta == "ok"){

                        window.location = localStorage.getItem("rutaActual");

                    }else{

                        swal({
                          title: "¡ERROR!",
                          text: "¡The email"+email+" is already registered with a different method to Facebook!",
                          type: "error",
                          confirmButtonText: "Cerrar",
                          closeOnConfirm: false
                        },

                        function(isConfirm){
                            if (isConfirm) {    

                             FB.getLoginStatus(function(response){

                                 if(response.status === 'connected'){     

                                    FB.logout(function(response){

                                        deleteCookie("fblo_300012410734892");

                                        setTimeout(function(){

                                            window.location=rutaOculta+"salir";

                                        },500)

                                    });

                                    function deleteCookie(name){

                                         document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';

                                    }

                                 }

                             })

                            } 
                        });

                    }

                }

            })

        }

    })

}

/*=============================================
CLOSE SESSION FROM FACEBOOK
=============================================*/

$(".salir").click(function(e){

    e.preventDefault();

     FB.getLoginStatus(function(response){

         if(response.status === 'connected'){     

            FB.logout(function(response){

                deleteCookie("fblo_300012410734892");

                console.log("salir");

                setTimeout(function(){

                    window.location=rutaOculta+"salir";

                },500)

            });

            function deleteCookie(name){

                 document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';

            }

         }

     })

})

问题在于,在statusChangeCallback中直接输入错误警报,并在控制台中向我显示

enter image description here

0 个答案:

没有答案
相关问题