我可以使用以下代码成功获取一些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
,request.execute
但看不到生日和电话号码,尽管我的测试个人资料确实包含这些信息。
如何从此 api 调用中获取此信息?