如何从Google API获取生日和电话号码信息?

时间:2018-07-27 10:18:17

标签: javascript google-api google-signin google-profiles-api

我可以使用以下代码成功获取一些 Google个人资料信息:

googlePlusInit: function() {
    var googleUser = {};
    gapi.load('auth2', function(){
        // Retrieve the singleton for the GoogleAuth library and set up the client.
        auth2 = gapi.auth2.init({
            client_id: '309999495252-2j0c662keglco3na7pnb3fl66b3p1v31.apps.googleusercontent.com',
            cookiepolicy: 'single_host_origin',
            scope: 'https://www.googleapis.com/auth/user.phonenumbers.read https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/user.birthday.read'
        });
        sanObj.googlePlusSign(document.getElementById('g-plus-sign'));
    });
},

googlePlusSign: function(element){
    //console.log(element.id);
    auth2.attachClickHandler(element, {},
        function(googleUser) {
            console.log(googleUser.getBasicProfile().getGivenName());
            console.log(googleUser.getBasicProfile().getFamilyName());
            console.log(googleUser.getBasicProfile().getEmail());   
            sanObj.apiClientLoaded()            
        }, 

        function(error) {
          alert(JSON.stringify(error, undefined, 2));
        }

    );
},

apiClientLoaded: function() {
    gapi.client.load('plus', 'v1', function() {
        var request = gapi.client.plus.people.get({'userId': 'me'});
        request.execute(function(resp) {
            console.log(resp);

        });
    });
},

resp的{​​{1}}中,我可以看到一些个人资料信息,但是看不到生日和电话号码,尽管我的测试个人资料中确实包含此信息。

如何从此api调用中获取此信息?

0 个答案:

没有答案