0

我正在遵循指南: https ://developers.google.com/people/v1/write-people

我的代码:

def main():
    """Shows basic usage of the Google People API
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('people', 'v1', http=http,
        discoveryServiceUrl='https://people.googleapis.com/$discovery/rest')

    contact2 = service.people().createContact(
        body={"names": [{"givenName": "John", "familyName": "Doe"}]}).execute()

    contact2()

if __name__ == '__main__':
    main()

当我运行时,我的错误:

~/quickstart.py
Traceback (most recent call last):
  File "~/quickstart.py", line 77, in <module>
    main()
  File "~/quickstart.py", line 66, in main
    contact2()
TypeError: 'dict' object is not callable

Process finished with exit code 1

我收到这个错误。如何有效地创建新联系人?

4

2 回答 2

1

你的问题是这一行: contact2() service.people().createContact返回字典作为响应,你试图调用它。

字典对象不是函数。

于 2017-10-26T09:26:01.933 回答
0

问题解决了,虽然我不明白为什么。我能够使用以下方法保存联系人:

contact2 = service.people().createContact(
        body={"names": [{"givenName": "John", "familyName": "Doe"}]})

contact2.execute()
于 2017-10-26T09:22:38.247 回答