You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google People API传入date对象时无法创建生日日历条目问题咨询

问题:Google People API设置生日后无法同步生成日历条目

我需要创建联系人并同步生成对应生日日历条目,因此调用Google People API设置生日信息。我设置的personFields参数为:

names,birthdays,phoneNumbers,memberships

请求传递的person对象如下:

{"phoneNumbers":[{"type":"work","value":"(266) 581-6706"}],"names":[{"unstructuredName":"Bradley"}],"birthdays":[{"date":{"year":2012,"month":10,"day":13}}],"memberships":[{"contactGroupMembership":{"contactGroupResourceName":"contactGroups/myContacts"}}]}

但调用API后返回的生日仅为"text": "10/13/2021"格式的字符串,该格式无法同步生成生日日历条目,我期望传入的结构化date对象能被正常识别处理,请问我是否遗漏了相关配置?
请求curl示例如下:

curl --request POST \
  'https://people.googleapis.com/v1/people:createContact?personFields=names%2Cbirthdays%2CphoneNumbers%2Cmemberships&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"phoneNumbers":[{"type":"work","value":"(266) 581-6706"}],"names":[{"unstructuredName":"Bradley"}],"birthdays":[{"date":{"year":2012,"month":10,"day":13}}],"memberships":[{"contactGroupMembership":{"contactGroupResourceName":"contactGroups/myContacts"}}]}' \
  --compressed

回答

你没有遗漏配置,这个问题是Google People API的默认字段处理逻辑导致的:你只传入了date结构化对象,API会默认将其转换为纯文本格式存储,无法被日历服务识别为可同步的生日条目。

修复方法

在birthdays数组的对应对象中,同时传入结构化date对象和格式为YYYY-MM-DD的text字段,两者的日期值必须完全一致,不要使用斜杠格式的日期字符串。

修改后的请求体birthdays部分示例:

"birthdays": [
  {
    "date": {
      "year": 2012,
      "month": 10,
      "day": 13
    },
    "text": "2012-10-13"
  }
]

效果验证

修改后重新调用接口,返回结果会同时保留结构化date对象和text字段,Google联系人服务会将该生日识别为结构化日期,自动同步到Google日历的生日日历列表中。


内容的提问来源于stack exchange,提问作者Code Guy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 13:15:03