【问题标题】:Google People API cannot get birthday yearGoogle People API 无法获取生日年份
【发布时间】:2016-10-01 09:38:02
【问题描述】:

这是我在 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 天。请帮忙。

【问题讨论】:

  • 那么,如果不在 google 帐户中将生日设置为公开,我就无法获取生日年份?有什么解决方法吗?因为我的应用需要注册用户资料的年份。它不仅会被我使用,还会被其他在我的应用中使用谷歌登录的人使用
  • 是的,没有用户许可你不能得到它
  • 好的。感谢您的帮助

标签: android google-people-api


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    缺少出生年份的另一个原因是您的生日是 1970 年 1 月 1 日。在这种情况下,API 不会返回您的生日。

    如果您在 Google plus 个人资料上禁用了年份显示,那么 PROFILE 将在 1 月 1 日返回,而 ACCOUNT 仍然不会返回任何内容。

    【讨论】:

    • Consumer G+ 将在 2 周内关闭,不确定 People API 是否仍处于活动状态。总的来说,整个问答环节很快就会变得非常不敬。
    • 人们不受关闭的影响 - 请参阅 stackoverflow.com/a/53939089/4096994
    【解决方案3】:

    People API 返回 2 个生日,第一个生日只有日期和月份,第二个生日也有年份。这是java代码的sn-p

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

    【讨论】:

    • 这不是真的。有时,它会返回两个生日。其他时候它返回一个生日。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多