Google Chat API 获取空间的消息列表

问题描述 投票:0回答:1

我正在尝试让 this example 在 Python 中工作。

def get_msg():
    creds = None
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', ['https://www.googleapis.com/auth/chat.spaces', 'https://www.googleapis.com/auth/chat.messages')

    chat = build('chat', 'v1', credentials=creds)
    result = chat.spaces().messages().list(name='spaces/123456789').execute()
    print(result)


def main():
    get_msg()

出现此错误:

Traceback (most recent call last):
  File "C:\30_py\google\chat\test_chat.py", line 64, in <module>
    main()
  File "C:\30_py\google\chat\test_chat.py", line 57, in main
    get_msg()
  File "C:\30_py\google\chat\test_chat.py", line 46, in get_msg
    result = chat.spaces().messages().list(name='spaces/123456789').execute()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Resource' object has no attribute 'list'

我在 API explorer 中测试了授权和空间名称,它有效。我能够使用不同的端点获取空间列表,因此凭证/令牌/逻辑可以工作。但是,我一直在尝试让端点正常工作,即能够修复此属性错误。任何想法和建议都值得赞赏。

python attributeerror google-chat
1个回答
0
投票

name
中没有
list()
参数。您需要将空间 ID 指定为
parent
作为
"spaces/{space}"
。 如有疑问,请使用 API 参考

© www.soinside.com 2019 - 2024. All rights reserved.