google api和javascript.获得生日和性别 [英] google api with javascript. get birthday and gender

查看:106
本文介绍了google api和javascript.获得生日和性别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这很简单,但找不到示例.
我正在使用基本的Google登录示例.带有标题标签(包括生日范围):

I think it must be simple but couldnt find an example.
I'm using the basic google signin example. with header tags (including birthday scope):

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

and a defualt login button in the html body:

<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?
我已经看到了许多有关使用范围的示例,但是找不到如何实际读取数据(生日)...对于性别而言,这是相同的,所以不要认为有一个特殊的范围那,我想它应该是基本个人资料info(?)
的一部分 预先感谢

All this works just fine, user is asked to grant permissions. and i get the general profile info. but i'm not sure how to obtain the birthday date, is it somehow in the returned object? do i need another call to the api?
I've seen lots of examples about using scopes but couldn't find how to actually read the data(birthday date)... same thing for gender, don't think there is a special scope for that, i guess it should be part of the basic profile info(?)
Thanks in advance

只是为了澄清,我知道我使用的是正确的范围.我不知道如何读取数据.例如,在用户通过身份验证之后-profile.getEmail()将返回电子邮件.生日会返回什么?

edit: just to clarify, i know i'm using the right scope. i don't know how to read the data. for example, after user authenticated - profile.getEmail() will return the email. what would return the birthday?

推荐答案

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

GoogleUser.getBasicProfile() Get the user's basic profile information.

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

Returns
A gapi.auth2.BasicProfile object. You can retrieve this object's properties with the following methods:
BasicProfile.getId() BasicProfile.getName()
BasicProfile.getImageUrl()
BasicProfile.getEmail()

此方法不返回生日.我知道要恢复生日的唯一方法是使用 people.get .

This method does not return birthday. The only way I know of to get birthday back would be to use people.get from the google+ api.

这篇关于google api和javascript.获得生日和性别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆