Google People API cannot get birthday year
Asked Answered
B

3

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.

Boner answered 1/10, 2016 at 9:38 Comment(6)
please check this ref : #19612857Inhere
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 appBarker
yes you can't get it without user permissionInhere
Ow ok. Thank You for your helpBarker
Try this: another question about missing fieldsKyd
I already try that. But I still cannot get the year if the user not disable the hide year button in google plus profile.Barker
A
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.

Allista answered 21/11, 2016 at 6:21 Comment(0)
G
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.

Gregoriagregorian answered 19/3, 2019 at 1:7 Comment(2)
Consumer G+ will shutdown in less than 2 weeks, not sure if the People API is even still active. in general, this whole Q&A will become quite irreverent soon.Consolata
People is unaffected by the shutdown - see https://mcmap.net/q/1629717/-will-people-get-method-be-affected-by-google-api-deprecationGregoriagregorian
P
-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;
        }
    }
Periodicity answered 14/10, 2018 at 8:43 Comment(1)
This is not true. Sometimes, it returns two birthdays. Other times it returns one birthday.Kareykari

© 2022 - 2024 — McMap. All rights reserved.