问题描述
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"
}
}
解决方法
您必须在删除和更新请求中都发送资源名称。
删除请求只需要资源名称。
更新请求需要资源名称和人员。 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”,这表明联系人在读取数据后发生了变化。客户应该获取最新的人并将他们的更新合并到最新的人中。
简而言之,您可能只使用 *