验证是否谷歌电子邮件是在ajax请求发送



我读了很多关于angular的文章,我真的是一个新手。我被要求为我工作的公司开发这个应用程序,用户需要使用他们的谷歌凭据登录。

到目前为止,这很简单,但我认为我把自己弄得太复杂了。到目前为止,我有以下内容:

  • Google登录按钮
  • 回调函数,将电子邮件保存到一个变量,并发送一个AJAX请求,将其保存在数据库中,并开始会话

问题:

  • Google Api说找不到回调函数。我很确定这是非常简单的东西,但我似乎真的找不到。

下面是我的相关angular代码:

app.controller('LoginController', function($scope){
        $scope.authResultErrorMessage = "";
        $scope.showAuthResultErrorMessage = false;
        $scope.userEmail = "";
        $scope.handleSignIn = function(authResult){
            console.log("I was called!");
            if(authResult){
                if(authResult['error'] != undefined){
                    $scope.showAuthResultErrorMessage = true;
                    $scope.authResultErrorMessage = "Hubo un error. Intente de nuevo. Si este error persiste, ponganse en contacto con el director de IT.";
                } else if(authResult['error'] === undefined){
                    gapi.client.load('plus', 'v1', loadProfileFromGoogle);
                }
            }
        };
        $scope.loadProfileFromGoogle = function(){
            var request = gapi.client.plus.people.get( {'userId' : 'me'} );
            request.execute(getEmail);
            console.log(request);
        };
        $scope.getEmail = function(obj){
            $scope.userEmail = obj['emails'].filter(function(v){
                return v.type === 'account';
            })[0].value;
            console.log($scope.userEmail);
            $scope.verifyUser($scope.userEmail);
        };
        $scope.verifyUser = function(email){
            $.get('controllers/verifyUser.php', {
                data: email,
            }, function(result){
                    console.log(result);
                    JSON.parse(result);
            });
        };
    });

下面是html代码:

<div ng-controller="LoginController as login">
    <span id="signin-button">
        <span
            class="g-signin"
            data-callback="login.handleSignIn"
            ng-click="login.handleSignIn"
            data-approvalprompt="force"
            data-clientid="201763423039-kdogu6vm1fgsj6hdnafn5k9otkj9ekjj.apps.googleusercontent.com"
            data-cookiepolicy="single_host_origin"
            data-requestvisibleactions="http://schemas.google.com/AddActivity"
            data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read">
        </span>
    </span>   
</div>

当我点击按钮时,一切都很顺利,我登录了,但在控制台上,显示以下消息:

名为"login"的回调函数。handleSignIn" not found cb=gapi. loadd_0:484

我已经砸了我的头几个小时了,现在试图弄清楚为什么函数没有被调用,或者对于这件事,如果有一个语法错误目前没有被突出显示存在。如果有人能帮忙,我会非常感激。

为什么不试试这个指令:

http://jeradbitner.com/angular-directive.g-signin/

最新更新