1

我在这里使用帖子:https ://developers.google.com/chat/how-tos/service-accounts#creating_and_using_a_service_account与 Google Chat API 进行交互。我创建了服务帐户 + 启用了 API 访问以及安装所有 python 依赖项/库。

但是,我收到以下错误:

Traceback (most recent call last):
  File "a.py", line 9, in <module>
    body={'text': 'Test message'}).execute()
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 131, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 937, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://chat.googleapis.com/v1/spaces/AAAAWtx0J9a/messages?alt=json returned "Invalid project number.". Details: "Invalid project number.">

代码:

from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
scopes = 'https://www.googleapis.com/auth/chat.bot'
credentials = ServiceAccountCredentials.from_json_keyfile_name('gcapi-13221-bcbc7fe2b54b.json', scopes)
chat = build('chat', 'v1', http=credentials.authorize(Http()))
resp = chat.spaces().messages().create(
    parent='spaces/AAAAWtx0J9a',
    body={'text': 'Test message'}).execute()
print(resp)

谁能解释一下我在这里缺少的东西?

非常感谢

4

0 回答 0