Google People API无法获得生日

问题描述 投票:6回答:3

这是我在stackoverflow中的第一个问题。当我试图获得用户生日年份时,我遇到了Google People API的问题。这是我的logcat的日志。

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

正如你所看到的,我可以得到月和日。但是,那里没有一年。即使我正在使用谷歌尝试它!来自https://developers.google.com/people/api/rest/v1/people/get。回应也没有给出年份。

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
   }
  }
 ]
}

在决定提出问题之前,我一直在努力弄清楚这一点并从stackoverflow搜索4天。请帮忙。

android google-people
3个回答
1
投票

如果您想验证此人的年龄,也许可以查看age range字段是否符合您的需求。你可以通过请求https://www.googleapis.com/auth/profile.agerange.read范围来获得它。


0
投票

People API返回2个生日,第一个生日只有日和月,第二个也有年。这是java代码的片段

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

0
投票

如果您的生日是1970年1月1日,那么出生年份错过的另一个原因是。在这种情况下,API将不会返回您的生日。

如果您在Google Plus配置文件中禁用了年份显示,那么PROFILE将返回1月1日,而ACCOUNT仍然不会返回任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.