google api用javascript。得到生日和性别

时间:2016-03-07 11:54:51

标签: javascript google-api

我认为它必须简单,但无法找到一个例子 我使用的是基本的google登录示例。带标题标签(包括生日范围):

<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正文中的defualt登录按钮:

<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()将返回电子邮件。什么会回来的生日?

1 个答案:

答案 0 :(得分:1)

GoogleUser.getBasicProfile()获取用户的基本个人资料信息。

  

返回
一个gapi.auth2.BasicProfile对象。你可以检索这个   对象的属性使用以下方法:
BasicProfile.getId()   BasicProfile.getName()
BasicProfile.getImageUrl()
  BasicProfile.getEmail()

此方法不会返回生日。我知道生日回来的唯一方法是使用google + api中的people.get