javascript - 如何从 Google 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
,request.execute
但看不到生日和电话号码,尽管我的测试个人资料确实包含这些信息。
如何从此 api 调用中获取此信息?
解决方案
推荐阅读
- php - 每次满足if语句时,如何为多维数组中的每个人添加一个int值到'i'
- jquery - 用户滚动时使用 jQuery 更改 rgba 背景颜色
- msbuild - 如何让 msbuild 识别另一个字母表中的字符?
- regex - 如何使用正则表达式排序?
- vb.net - 如何使搜索栏等于 vb.net 中的 Windows 文件资源管理器?
- django - 如何为单个视图制作 404 页面?
- arrays - 矩阵/二维numpy数组中的着色条目?
- python - 如何绘制单点初始化?
- .net - MVC1000 警告死锁的根本原因是什么(使用 IHtmlHelper.Partial 可能导致应用程序死锁......)
- vba - 自动导出访问表数据以填充模板 Excel 工作表