【问题标题】:Any way to bypass Etag check in People API?有什么方法可以绕过 People API 中的 Etag 检查?
【发布时间】:2021-07-25 23:22:15
【问题描述】:

Google 通讯录允许我们通过传递 * 而不是联系人当前的 Etag 来绕过 Etag 验证以进行编辑/删除请求。

Google Contacts API documentation

注意:特殊的 Etag 值 * 可用于绕过此验证并处理更新,而不管来自其他客户端的更新。

有没有类似的方法可以绕过People API中编辑/删除的Etag验证?

如果在更新期间未在 Person 对象中发送 etag 值,则会面临以下错误。值“ * ”在 People API 中也不起作用。

请求:

{
  "emailAddresses": [
    {
      "displayName": "test1@gmail.com",
      "value": "test1@gmail.com",
      "type": "home"
    }
  ]
}

回复:

{
  "error": {
    "code": 400,
    "message": "Request must set person.etag or person.metadata.sources.etag for the source that is being updated.",
    "status": "INVALID_ARGUMENT"
  }
}

【问题讨论】:

    标签: google-contacts-api google-people-api


    【解决方案1】:

    您必须在删除和更新请求中都发送资源名称。

    删除请求只需要资源名称。

    更新请求需要资源名称和人员。 IMO 最好的更新方法是先获取 Person,然后更新数据,然后将其推回。

    如果您不使用他们的 API 之一,也需要 updateMask https://developers.google.com/people/api/rest/v1/people/updateContact?hl=en

    https://developers.google.com/people/api/rest/v1/people/updateContact?hl=en

    如果 person.metadata.sources.etag 与联系人的 etag 不同,则服务器返回 400 错误,原因为“failedPrecondition”,这表明联系人在读取其数据后发生了变化。客户应该获取最新的人并将他们的更新合并到最新的人中。

    简而言之,您可能只使用 * 就不走运了

    【讨论】:

    • 在 updateMask 中提供“names,addressess”。但是,如果我需要更改 givenName,并且我将 updateMask 设置为“names.givenName”,则会引发以下错误:{ "error": { "code": 400, "message": "Invalid updatePersonFields mask path: \"names.given_name\". Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/updateContact.", "status": "INVALID_ARGUMENT" } } 知道如何提供此掩码吗?
    猜你喜欢
    • 2022-06-15
    • 2018-03-03
    • 2017-08-31
    • 2020-06-01
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    相关资源
    最近更新 更多