7

this is my first question in stackoverflow. I have a problem with Google People API when I'm trying to get user birthday year. Here's the log from my logcat.

D/FitPartners: {"date":{"day":20,"month":1},"metadata":{"primary":true,"source":{"id":"1....41","type":"PROFILE"}}}

As you can see, I can get the month and day just fine. But, there's no year in there. Even when I'm using google Try it! from https://developers.google.com/people/api/rest/v1/people/get. The response don't give the year too.

Response

200 OK

- Show headers -

{
 "resourceName": "people/1.......41",
 "etag": "r....a4o=",
 "birthdays": [
  {
   "metadata": {
    "primary": true,
    "source": {
     "type": "PROFILE",
     "id": "1........41"
    }
   },
   "date": {
    "month": 1,
    "day": 20
   }
  }
 ]
}

I've been trying to figure out about this and searching from stackoverflow for 4 days before deciding to make a questions. Please help.

  • please check this ref : http://stackoverflow.com/questions/19612357/retrieving-date-of-birth-and-marital-status-with-google-oauth-api – Damini Mehra Oct 01 '16 at 09:45
  • So, I can't get the birthday year without setting the birthday as public in the google account? Is there any work around for this? cause my app need the year for registering the user profile. And it will be used not only by me but other people who use the google login in my app – Tommy Hart'no Oct 01 '16 at 10:02
  • yes you can't get it without user permission – Damini Mehra Oct 01 '16 at 10:50
  • Ow ok. Thank You for your help – Tommy Hart'no Oct 01 '16 at 15:47
  • Try this: [another question about missing fields](http://stackoverflow.com/questions/35604406/retrieving-information-about-a-contact-with-google-people-api-java) – A-S Oct 12 '16 at 10:09
  • I already try that. But I still cannot get the year if the user not disable the hide year button in google plus profile. – Tommy Hart'no Oct 12 '16 at 14:42

3 Answers3

1

If you want to verify the person's age, perhaps see if the age range field meets your needs. You can get it by requesting the https://www.googleapis.com/auth/profile.agerange.read scope.

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
Amos Yuen
  • 1,420
  • 1
  • 9
  • 19
0

One additional reason for a missing birth year is if your birthday is Jan 1, 1970. In that case, the API will not return your birthday.

If you have disabled year display on your Google plus profile, then PROFILE will return Jan 1, and ACCOUNT will still return nothing.

-1

People API returns 2 birthdays, the first birthday only has day and month, the second has also year. Here is the snippet for java code

public static String getBirthday(Person person) {
        try {
            List<Birthday> birthdayList = person.getBirthdays();
            if (birthdayList == null) return Utils.EMPTY_STRING;
            Date date = null;
            for (Birthday birthday : birthdayList) {
                date = birthday.getDate();
                if (date != null && date.size() >= 3) break; // 3 means included day, month and year
                else date = null;
            }
            if (date == null) return Utils.EMPTY_STRING;
            Calendar calendar = Calendar.getInstance();
            calendar.set(date.getYear(), date.getMonth() - 1, date.getDay());
            return Utils.convertDateToString(calendar);
        } catch (Exception e) {
            Utils.handleException(e);
            return Utils.EMPTY_STRING;
        }
    }
thanhbinh84
  • 17,876
  • 6
  • 62
  • 69