Angular 如何获得用户';从google登录中查看s的生日和性别
我正在尝试在我的angular应用程序中实现google登录。谷歌返回姓名、电子邮件、个人资料图片、ID、访问令牌。我怎么才能得到用户的生日和性别。我试过很多方法,但都不管用 我试图评测.getGender()和.getBirthday()它抛出了错误Angular 如何获得用户';从google登录中查看s的生日和性别,angular,google-api,google-oauth,Angular,Google Api,Google Oauth,我正在尝试在我的angular应用程序中实现google登录。谷歌返回姓名、电子邮件、个人资料图片、ID、访问令牌。我怎么才能得到用户的生日和性别。我试过很多方法,但都不管用 我试图评测.getGender()和.getBirthday()它抛出了错误 googleSDK() { window['googleSDKLoaded'] = () => { window['gapi'].load('auth2', () => { this.auth2 = wind
googleSDK() {
window['googleSDKLoaded'] = () => {
window['gapi'].load('auth2', () => {
this.auth2 = window['gapi'].auth2.init({
client_id: 'YOUR_CLIENT_ID',
cookiepolicy: 'single_host_origin',
scope: 'profile email'
});
this.prepareLoginButton();
});
}
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://apis.google.com/js/platform.js?onload=googleSDKLoaded";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'google-jssdk'));
}
ngOnInit() {
this.googleSDK();
}
prepareLoginButton() {
this.auth2.attachClickHandler(this.loginElement.nativeElement, {},
(googleUser) => {
let profile = googleUser.getBasicProfile();
console.log('Token || ' + googleUser.getAuthResponse().id_token);
console.log('ID: ' + profile.getId());
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
//YOUR CODE HERE
}, (error) => {
alert(JSON.stringify(error, undefined, 2));
});
}
您需要以下作用域才能访问该数据
- 查看您的完整出生日期:
- 查看您的性别:
您需要以下作用域才能访问该数据
- 查看您的完整出生日期:
- 查看您的性别:
我当前的作用域看起来是这样的-作用域:“配置文件电子邮件”,但在控制台中,我没有得到任何性别和生日信息。您是否重新验证了该应用程序?它是否会弹出并要求您授予对其他作用域的访问权限?我不是一个有棱角的人,所以我不能帮你更多。您需要请求适当的作用域并通过people api。(这可能是谷歌用户所做的)是的,谷歌问我是否想公开我的性别和生日,我已经允许了。但是我不知道为什么这两个没有显示你检查过你的谷歌帐户是否设置为公共吗?是的,我检查过它是否设置为公共。我当前的作用域看起来像这样-作用域:'配置文件电子邮件',但在控制台中我没有任何性别和生日你是否重新授权了该应用程序?它是否弹出并要求你授予访问权限额外的作用域?我不是一个有棱角的人,所以我不能帮你更多。您需要请求适当的作用域并通过people api。(这可能是谷歌用户所做的)是的,谷歌问我是否想公开我的性别和生日,我已经允许了。但是我不知道为什么这两个都没有显示出来。你检查过你的谷歌帐户是否设置为公共吗?是的,我检查过它是否设置为公共。