【发布时间】:2016-03-07 11:54:50
【问题描述】:
我认为它一定很简单,但找不到示例。
我正在使用基本的谷歌登录示例。带有标题标签(包括生日范围):
<meta name="google-signin-scope" content="profile email https://www.googleapis.com/auth/user.birthday.read" />
<meta name="google-signin-client_id" content="xxx my id xxx" />
<script src="https://apis.google.com/js/platform.js" async defer></script>
以及 html 正文中的默认登录按钮:
<div id="gsignin" class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
和js:
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log(googleUser);
console.log("ID: " + profile.getId());
console.log("Name: " + profile.getName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
g_token = googleUser.getAuthResponse().id_token;
}
这一切都很好,用户被要求授予权限。我得到了一般的个人资料信息。但我不确定如何获得生日日期,它是否在返回的对象中?我需要再次调用 api 吗?
我看过很多关于使用范围的示例,但找不到如何实际读取数据(生日日期)......性别也一样,不要认为有特殊的范围那,我想它应该是基本个人资料信息的一部分(?)
提前致谢
编辑: 澄清一下,我知道我使用了正确的范围。我不知道如何读取数据。例如,用户通过身份验证后 - profile.getEmail() 将返回电子邮件。什么会返回生日?
【问题讨论】:
-
生日在 JSON 中并不总是可用的。只有共享生日的用户才拥有生日属性。
-
你的问题没有问范围,但答案是一样的。
-
谢谢。你能详细说明一下吗?假设它是公开的,我会在 profile.getBirthday() 中找到它吗?还是我需要打另一个电话
标签: javascript google-api