【问题标题】:Google People API - Birthday - Date object is not returned in GET requestsGoogle People API - 生日 - GET 请求中不返回日期对象
【发布时间】:2021-10-03 20:45:39
【问题描述】:

在 Google People - people.connections.list 和其他 GET API 中,某些联系人不返回生日字段的日期对象。已使用完整的人员范围进行身份验证 [https://www.googleapis.com/auth/contacts]。

我们也不知道要解析的“文本”字段的格式,因为参数可以有任何随机字符串。

如何解析用户的生日?什么时候不返回 Date 对象?

样品申请

https://people.googleapis.com/v1/people/me/connections?pageSize=100&requestSyncToken=true&personFields=birthdays

生日示例回复

    {
        "birthdays": [
            {
                "metadata": {
                    "source": {
                        "id": "3ebd95668aeed9d7",
                        "type": "CONTACT"
                    },
                    "primary": true
                },
                "text": "2000-07-24"
            }
        ],
        "resourceName": "people/c4520933868599957975",
        "etag": "<etag>"
    },
    {
        "birthdays": [
            {
                "metadata": {
                    "source": {
                        "id": "5f5712ce0861c5b0",
                        "type": "CONTACT"
                    },
                    "primary": true
                },
                "text": "1880-03-11"
            }
        ],
        "resourceName": "people/c6869980432690169264",
        "etag": "<etag>"
    },
    {
        "birthdays": [
            {
                "date": {
                    "month": 1,
                    "year": 1990,
                    "day": 26
                },
                "metadata": {
                    "source": {
                        "id": "a16dde58e814a36",
                        "type": "CONTACT"
                    },
                    "primary": true
                },
                "text": "01/26/1990"
            }
        ],
        "resourceName": "people/c727012367875000886",
        "etag": "<etag>"
    },
    {
        "birthdays": [
            {
                "date": {
                    "month": 1,
                    "year": 1998,
                    "day": 1
                },
                "metadata": {
                    "source": {
                        "id": "f350f568dd11db1",
                        "type": "CONTACT"
                    },
                    "primary": true
                },
                "text": "Jan 1, 1998"
            }
        ],
        "resourceName": "people/c1095798948755479985",
        "etag": "<etag>"
    },
    {
        "birthdays": [
            {
                "metadata": {
                    "source": {
                        "id": "3652e00f0d28c9f4",
                        "type": "CONTACT"
                    },
                    "primary": true
                },
                "text": "random string accept"
            }
        ],
        "resourceName": "people/c3914437381388290548",
        "etag": "<etag>"
    }
]

【问题讨论】:

  • 你好,你能把你正在使用的范围包括进来吗?
  • 使用完整范围 - googleapis.com/auth/contacts。我会把它添加到问题中

标签: google-people-api


【解决方案1】:

birthday 字段,既可以是日期也可以是文本,不保证相同。

【讨论】:

  • 是的,这很好,但在少数联系人中不会返回 Date 对象。
  • 是的,因为日期不是必填字段。该方法只需要文本 OR 日期。所以这意味着对于那些没有日期字段的生日,它不会被返回。
  • 那么在那些没有发送Date对象的情况下,我们如何解析文本字段呢? [考虑到文本可以是任何随机字符串]。
  • 我猜你必须构建一个考虑到这一点的解析器。或者您可以请求列表中的所有生日并使用域范围授权将它们添加到您的用户
  • 这是不可能的,因为我们必须每周运行 Google People 完全同步,而且生日会再次消失。然后我们每周都会有额外的要求。目前,我们的解决方案是我们为大多数可预测的日期格式添加了处理。如果遇到任何未处理的格式,我们将逐步添加。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 2018-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多