人脉中的删除联系人功能 API 不起作用:方法:people.deleteContact
Delete contact function in People API not work: Method: people.deleteContact
现在我尝试使用 python 为联系人编写一个 CMS 项目,但我遇到了一些问题。
我编写了这个定义,但它不适用于 google 人 API。
https://developers.google.com/people/v1/contacts
日志
File "/Users/nguyenngoclinh/.conda/envs/1z_vietnam/lib/python3.7/site-packages/googleapiclient/http.py", line 907, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://people.googleapis.com/v1/%7B'people/c9194159806299427121'%7D:deleteContact?alt=json returned "Not Found">
删除功能如下
def delete_contacts_with_resourceName(creds,http,number_of_contact):
# Call the People API
service = build('people', 'v1', credentials=creds)
print('Ban dang xoa', number_of_contactcontact, 'contacts')
results = service.people().connections().list(
resourceName='people/me',
pageSize=number_of_contactofcontact,
personFields='names,emailAddresses,phoneNumbers,emailAddresses,addresses').execute()
service = discovery.build('people', 'v1', http=http,
discoveryServiceUrl='https://people.googleapis.com/$discovery/rest')
connections = results.get('connections', [])
for person in connections:
abcd = person.get('resourceName')
service.people().deleteContact(resourceName={abcd}).execute()
但是下面的 creat contact def 也有效。
def creat_a_google_contact(http):
# POST / v1 / people: createContact
# HTTP / 1.1
# Body: {"names": [{"givenName": "John", "familyName": "Doe"}]}
# Host: people.googleapis.com
service = discovery.build('people', 'v1', http=http,
discoveryServiceUrl='https://people.googleapis.com/$discovery/rest')
service.people().createContact(body={
"names": [
{
'givenName': "Nguyen Ngoc Linh",
"familyName": "29N2359 BMW 325i"
}
],
"phoneNumbers": [
{
'value': "0979955664"
}
],
"emailAddresses": [
{
'value': "bk.nguyenlinh@gmail.com"
}
],
"addresses": [
{
"streetAddress": "So 1 ngo 85 Lang Ha",
"extendedAddress": "Ba Dinh",
"city": "Ha Noi",
"region": "Ha Noi",
"postalCode": "10000",
"country": "Vietnam",
"countryCode": "84"
}
]
}).execute()
def main,请大家帮帮我
def main():
creds = get_credentials(FLOW)
# print_list_google_contact_with_number_of_contacts(creds,1000)
http=get_http(creds)
#creat_a_google_contact(http)
# print_result(creds)
delete_contacts_with_resourceName(creds,http,1000)
#print_resourceName(creds, 2000)
资源名称格式不正确:
如果您尝试通过 Try this API
from this page 删除联系人,您会注意到要访问的 URL 具有以下形状:
https://people.googleapis.com/v1/people/c7142462727258425368:deleteContact
其中 people/c7142462727258425368
是联系人的 resourceName
。也就是说,资源名称没有单引号 (' '
) 也没有括号 ({ }
)。 由于资源名称可能未在 URL 中格式化,API 无法识别它,导致 404 错误。
这就是您的请求失败的原因:
https://people.googleapis.com/v1/%7B'people/c9194159806299427121'%7D:deleteContact
要解决此问题,只需在将 abcd
作为资源名称提供时移除括号。应该是这样的:
service.people().deleteContact(resourceName=abcd).execute()
参考:
现在我尝试使用 python 为联系人编写一个 CMS 项目,但我遇到了一些问题。
我编写了这个定义,但它不适用于 google 人 API。 https://developers.google.com/people/v1/contacts
日志
File "/Users/nguyenngoclinh/.conda/envs/1z_vietnam/lib/python3.7/site-packages/googleapiclient/http.py", line 907, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://people.googleapis.com/v1/%7B'people/c9194159806299427121'%7D:deleteContact?alt=json returned "Not Found">
删除功能如下
def delete_contacts_with_resourceName(creds,http,number_of_contact):
# Call the People API
service = build('people', 'v1', credentials=creds)
print('Ban dang xoa', number_of_contactcontact, 'contacts')
results = service.people().connections().list(
resourceName='people/me',
pageSize=number_of_contactofcontact,
personFields='names,emailAddresses,phoneNumbers,emailAddresses,addresses').execute()
service = discovery.build('people', 'v1', http=http,
discoveryServiceUrl='https://people.googleapis.com/$discovery/rest')
connections = results.get('connections', [])
for person in connections:
abcd = person.get('resourceName')
service.people().deleteContact(resourceName={abcd}).execute()
但是下面的 creat contact def 也有效。
def creat_a_google_contact(http):
# POST / v1 / people: createContact
# HTTP / 1.1
# Body: {"names": [{"givenName": "John", "familyName": "Doe"}]}
# Host: people.googleapis.com
service = discovery.build('people', 'v1', http=http,
discoveryServiceUrl='https://people.googleapis.com/$discovery/rest')
service.people().createContact(body={
"names": [
{
'givenName': "Nguyen Ngoc Linh",
"familyName": "29N2359 BMW 325i"
}
],
"phoneNumbers": [
{
'value': "0979955664"
}
],
"emailAddresses": [
{
'value': "bk.nguyenlinh@gmail.com"
}
],
"addresses": [
{
"streetAddress": "So 1 ngo 85 Lang Ha",
"extendedAddress": "Ba Dinh",
"city": "Ha Noi",
"region": "Ha Noi",
"postalCode": "10000",
"country": "Vietnam",
"countryCode": "84"
}
]
}).execute()
def main,请大家帮帮我
def main():
creds = get_credentials(FLOW)
# print_list_google_contact_with_number_of_contacts(creds,1000)
http=get_http(creds)
#creat_a_google_contact(http)
# print_result(creds)
delete_contacts_with_resourceName(creds,http,1000)
#print_resourceName(creds, 2000)
资源名称格式不正确:
如果您尝试通过 Try this API
from this page 删除联系人,您会注意到要访问的 URL 具有以下形状:
https://people.googleapis.com/v1/people/c7142462727258425368:deleteContact
其中 people/c7142462727258425368
是联系人的 resourceName
。也就是说,资源名称没有单引号 (' '
) 也没有括号 ({ }
)。 由于资源名称可能未在 URL 中格式化,API 无法识别它,导致 404 错误。
这就是您的请求失败的原因:
https://people.googleapis.com/v1/%7B'people/c9194159806299427121'%7D:deleteContact
要解决此问题,只需在将 abcd
作为资源名称提供时移除括号。应该是这样的:
service.people().deleteContact(resourceName=abcd).execute()