问题描述
我使用 Google People API v1.otherContacts.copyOtherContactToMyContactsGroup
(reference) 将联系人从“其他联系人”复制到“myContacts”联系人组。我现在想使用相同的 API 从“其他联系人”中删除原始联系人。
REST 资源 v1.otherContacts
(reference) 未列出 DELETE
操作。
我尝试使用 v1.people.deleteContact
(reference) 传递我的“其他联系人”的资源名称:
import pickle
from googleapiclient.discovery import build
with open('token.pickle','rb') as token:
creds = pickle.load(token)
people_api = build('people','v1',credentials=creds)
people_service = people_api.people()
response = people_service.deleteContact(resourceName='otherContacts/c1971897568350947161').execute()
但我收到一条错误消息:
TypeError: 参数“resourceName”值“otherContacts/c1971897568350947161”与模式“^people/[^/]+$”不匹配
看起来 v1.people.deleteContact
无法删除“其他联系人”中的联系人。
如何以编程方式从“其他联系人”中删除联系人?
编辑:基于@DaimTo 的 suggestion below,我尝试将资源名称中的 otherContacts/
替换为 people/
并调用 v1.people.deleteContact
API,但我收到一条错误消息:
googleapiclient.errors.HttpError:
解决方法
我建议查阅 Produce and Consume Data
的文档必填。要删除的联系人的资源名称。
DELETE https://people.googleapis.com/v1/{resourceName=people/*}:deleteContact
这意味着它应该是 people/c1971897568350947161
,假设这是您要删除的用户的 ID c1971897568350947161
。
根据 Google 的以下公告,其他联系人似乎是只读的:https://developers.google.com/contacts/v3/announcement
新的 People API 具有与旧版联系人相同的功能 所有功能的 API,除了“其他 联系人”:
管理员通过以下方式对“其他联系人”拥有只读权限 新的范围。将 mutate/write 信号发送回“Other 联系人”不受支持,您的用户必须添加其他 如果他们希望更新其数据字段,请作为我的联系人联系。