Python 使用People Api v3搜索google联系人?

Python 使用People Api v3搜索google联系人?,python,python-3.x,google-contacts-api,google-people-api,Python,Python 3.x,Google Contacts Api,Google People Api,我正在尝试使用google People API按姓名字段搜索一个人。以下是代码示例: service = build('people', 'v1', credentials=creds) request = service.people().searchContacts(pageSize=10, query="A", readMask="names") print(request.body) # results in None, but there is

我正在尝试使用google People API按姓名字段搜索一个人。以下是代码示例:

service = build('people', 'v1', credentials=creds)
request = service.people().searchContacts(pageSize=10, query="A", readMask="names")
print(request.body) # results in None, but there is a lot of contacts in my list starting from "A". 
我使用了以下链接:

范围是

我需要一种使用姓名掩码返回联系人列表的方法(例如,使用“f”、“f”、“Foo”等可以找到名为“Foo bar”的人)。

回答: 您没有执行请求,只是引用了它

更多信息: 在Python中,没有定义的
return
的方法将始终返回
None

由于您没有发出请求,因此没有获得返回值,因此您将看到显示
none

代码修复: 您需要像这样执行请求:

service.people().searchContacts(pageSize=10, query="A", readMask="names").execute()
此外,响应对象没有属性
body
,因此需要使用

print(request.results)
查看响应文本

我希望这对你有帮助