将Python与Google People API结合使用otherContacts.copyOtherContactToMyContactsGroup方法

问题描述

我正在尝试使用Python执行请求以更新“其他联系人”中的联系人。我可以创建一个这样的请求对象

oRequest = servPeople.otherContacts().copyOtherContactToMyContactsGroup(resourceName = 'otherContacts/c5014863774837996295')

但我需要指定一个copyMask,例如'emailAddresses'

本文档Creating API requests and handling responses 似乎显示了如何指定此类请求的主体,并根据此Method: otherContacts.copyOtherContactToMyContactsGroup

我认为请求正文应为{ "copyMask": 'emailAddresses' },并且请求对象具有此方法,因此我可以指定oRequest.body = { "copyMask": 'emailAddresses' }

但是当我然后尝试oRequest.execute()时,我收到此消息:

回溯(最近通话最近): 发送中的文件“ C:\ Users \ * \ Anaconda3 \ lib \ http \ client.py”,行977 self.sock.sendall(数据) sendall中的文件“ C:\ Users * \ Anaconda3 \ lib \ ssl.py”,行1012 使用memoryview(data)作为视图,view.cast(“ B”)作为byte_view: TypeError:memoryview:需要一个类似字节的对象,而不是'str'。

解决方法

好-做到了:

body = {"copyMask": 'emailAddresses,names,phoneNumbers'}

result = servPeople.otherContacts().copyOtherContactToMyContactsGroup(resourceName = 'otherContacts/c5014863774837996295',body = body).execute()

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...