【问题标题】:Search google contact using People Api v3?使用 People Api v3 搜索谷歌联系人?
【发布时间】:2021-05-15 21:14:04
【问题描述】:

我正在尝试使用 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 python-3.x google-contacts-api google-people-api


    【解决方案1】:

    答案:

    你没有执行你的请求,只是引用它。

    更多信息:

    在 Python 中,没有定义 return 的方法将始终返回 None

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

    代码修复:

    你需要像这样执行请求:

    service.people().searchContacts(pageSize=10, query="A", readMask="names").execute()
    

    另外,响应对象没有属性body,所以你需要使用

    print(request.results)
    

    查看响应文本。

    【讨论】:

      猜你喜欢
      • 2020-12-07
      • 2021-03-26
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多