【问题标题】:Why I am unable to get email-id from Google plus api with angular-google-plus module?为什么我无法使用 angular-google-plus 模块从 Google plus api 获取电子邮件 ID?
【发布时间】:2017-01-05 22:06:25
【问题描述】:

编写下面的代码是为了使用 angular-google-plus 模块登录。我正在获取用户信息作为响应,例如姓氏、姓名、用户名、图像,但 emailId 除外。

  GooglePlus.login().then(function(response) {
    GooglePlus.getUser().then(function(response) {
       console.log(response);
     });
  },
  function(err) {
      console.log(err);
  });
 };

【问题讨论】:

标签: angularjs google-plus


【解决方案1】:

试试这个 GooglePlus.getProfile().then(function (user) { console.log(user);});

【讨论】:

    【解决方案2】:

    添加后我可以获取电子邮件 ID:

    GooglePlusProvider.setScopes('https://www.googleapis.com/auth/userinfo.email');

    之前

    GooglePlusProvider.init

    这对我有用:

    <!DOCTYPE html>
    <html>
    
      <head>
        <title>DOM Test</title>
        <script src="http://code.angularjs.org/1.0.8/angular.js"></script>
        <script src="https://rawgithub.com/mrzmyr/angular-google-plus/master/dist/angular-google-plus.min.js"></script>
        <script>
    
        var app = angular.module('app', ['googleplus']);
    
        app.config(['GooglePlusProvider', function(GooglePlusProvider) {
          GooglePlusProvider.setScopes('https://www.googleapis.com/auth/userinfo.email');
    
             GooglePlusProvider.init({
               clientId: 'give client id here',
               apiKey: 'give client id here'
             });
        }]);
    
        app.controller('AuthCtrl', ['$scope', 'GooglePlus', function ($scope, GooglePlus) {
            $scope.login = function () {
              GooglePlus.login().then(function (authResult) {
                  console.log(authResult);
    
                  GooglePlus.getUser().then(function (user) {
                      console.log(user);
                  });
              }, function (err) {
                  console.log(err);
              });
            };
        }])
        </script>
      </head>
    
      <body ng-app="app" ng-controller="AuthCtrl">
        <a href="javascript:void(0);" ng-click="login()">Login with Google Plus</a>
      </body>
    
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      • 2015-07-03
      相关资源
      最近更新 更多