成功登录后,Google登录/获取数据

时间:2017-08-21 12:37:03

标签: google-api google-oauth google-login

我已将Google第三方身份验证添加到我的网络应用程序中。谷歌登录工作正常,我已成功登录。我想要做的是登录谷歌后获取用户数据。这是我负责登录的功能。 `

/*Function which runs the google login feature*/
        $scope.onGoogleLogin  = function () {
            var myParams = {
                'clientid' : '******.apps.googleusercontent.com', //Client ID
                'cookiepolicy' : 'single_host_origin',
                'callback' : function (result) {
                    if(result['status']['signed_in']) {
                        var request = gapi.client.plus.people.get(
                            {
                                "userId": 'me'
                            }
                        );
                        request.execute(function (resp) {
                            $scope.$apply(function () {
                                    $scope.username = resp.displayName;
                                    $scope.email = resp.emails[0].value;
                            })
                        });
                    }
                }, //callback function
                'approvalprompt':'force',
                'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read'
            };
            gapi.auth.signIn(myParams);
            $scope.isGoogleLoginWorking = true;
        };

`

我在这一行收到错误。

var request = gapi.client.plus.people.get

这是错误:

  

未捕获的TypeError:无法读取未定义的属性'people'

1 个答案:

答案 0 :(得分:0)

更新

`*/Function which runs the google login feature*/
        $scope.onGoogleLogin  = function () {
            var myParams = {
                'clientid' : '******.apps.googleusercontent.com', //Client ID
                'cookiepolicy' : 'single_host_origin',
                'callback' : function (result) {
                    if (result['status']['signed_in']) {
                       gapi.client.load('plus','v1', function () { //This solved the problem 
                            var request = gapi.client.plus.people.get({
                                'userId': 'me',
                            });
                            request.execute(function (resp) {
                                $scope.$apply(function () {
                                    var username = resp.displayName;
                                    $scope.signUpModel.UserEmail = resp.emails[0].value;
                                    $scope.isGoogleLoginWorking = true;
                                    $scope.stringSplitter(username);
                                    $scope.submitCreatedUsersSocial();
                                });
                            });
                        });
                    }
                }, //callback function
                'approvalprompt':'force',
                'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read'
            };
            gapi.auth.signIn(myParams);
            $scope.isGoogleLoginWorking = true;
        };`