4

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>

and a defualt login button in the html body:

<div id="gsignin" class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>

and 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;
  }

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

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?

Ron K
  • 109
  • 1
  • 9

1 Answers1

1

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

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()

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.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • do I need to init another/different gapi object using another library? I have a "live" gapi object, i guess it's created by the included script https://apis.google.com/js/platform.js but if i try `gapi.client.load('plus', 'v1', function () {...});` i get js error "Cannot read property 'load' of undefined" – Ron K Mar 08 '16 at 10:42
  • 1
    Yup you will need a different service a google+ api service https://github.com/googleplus/gplus-quickstart-javascript/blob/master/index.html I am not a javaScript expert found you that though its the official sample project. – Linda Lawton - DaImTo Mar 08 '16 at 10:46
  • after adding Google+ api in the api manager and after adding ref to https://apis.google.com/js/client.js I can now call `gapi.client.load('plus', 'v1', function () {...});` but I'm still not getting the birthday in the response although I made sure it is public (testing on my own account). also it's strange that I now use both client.js and platform.js and i guess there are 2 "live" gapi objects. don't think this is the intended implementation... – Ron K Mar 13 '16 at 15:59
  • got it to work. my public settings were not correct. still not clear as to these 2 sign in options and 2 script references, does Google+ sign in supposed to replace Google sign in – Ron K Mar 13 '16 at 16:13