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