Reputation: 123
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.
Upvotes: 7
Views: 2526
Reputation: 168
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.
Upvotes: 0
Reputation: 18454
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;
}
}
Upvotes: -1
Reputation: 1459
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.
Upvotes: 1