【问题标题】:Delete "Other Contact" using Python with Google People API使用 Python 和 Google People API 删除“其他联系人”
【发布时间】:2021-06-05 07:09:14
【问题描述】:

我使用 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,我尝试用people/ 替换资源名称中的otherContacts/ 并调用v1.people.deleteContact API,但我收到一条错误消息:

googleapiclient.errors.HttpError: https://people.googleapis.com/v1/people/c1971897568350947161:deleteContact?alt=json 返回“ generic::NOT_FOUND: Contact person resources are not found.”。详细信息:“[{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'resourceNames[0]', 'description': '找不到资源。 '}]}]">

【问题讨论】:

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


    【解决方案1】:

    我建议查阅 people.deleteContact 的文档

    必填。要删除的联系人的资源名称。

    DELETE https://people.googleapis.com/v1/{resourceName=people/*}:deleteContact
    

    这意味着它应该是people/c1971897568350947161,假设这是您要删除的用户的ID c1971897568350947161

    【讨论】:

    • 我刚试过,这不起作用。我不能只用people/ 替换资源名称中的otherContacts/ 并调用v1.people.deleteContact。我收到错误消息:“googleapiclient.errors.HttpError: people.googleapis.com/v1/people/… returned “ generic::NOT_FOUND: Contact person resources are not found.”。详细信息:“[{ '@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'resourceNames[0]', 'description': '找不到资源。'}]}] ">"。
    【解决方案2】:

    根据 Google 的此公告,其他联系人似乎是只读的:https://developers.google.com/contacts/v3/announcement

    新的 People API 具有与旧版联系人相同的功能 所有功能的 API,“其他”除外 联系人”:

    管理员通过以下方式对“其他联系人”拥有只读权限 新的范围。将变异/写入信号发送回“其他 不支持“联系人”,您的用户必须添加“其他” 如果他们希望更新其数据字段,请作为我的联系人联系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      • 2016-10-18
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多