问题描述
我正在尝试使用 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".
我使用了以下链接:
https://developers.google.com/people/v1/contacts#python
https://googleapis.github.io/google-api-python-client/docs/dyn/people_v1.people.html#get
https://developers.google.com/people/quickstart/python
范围是 https://www.googleapis.com/auth/contacts.readonly。
我需要一种使用姓名掩码返回联系人列表的方法(例如,应使用“f”、“F”、“foo”等找到名为“Foo bar”的人)。
解决方法
答案:
你不是在执行你的请求,只是在引用它。
更多信息:
在 Python 中,没有定义 return
的方法将始终返回 None
。
由于您没有发出请求,因此没有获得返回值,因此您看到的是 none
。
代码修复:
您需要像这样执行请求:
service.people().searchContacts(pageSize=10,query="A",readMask="names").execute()
此外,响应对象没有属性 body
,因此您需要使用
print(request.results)
查看回复文本。
希望对你有帮助!