4

I'm following this article to create a message in Google Chat via services account. However when I compile the code, I got the following message:

Traceback (most recent call last): File "googlechat-api.py", line 27, in resp = chat.spaces().messages().create( File "C:\Users\tdi5539\Anaconda3\lib\site-packages\googleapiclient_helpers.py", line 134, in positional_wrapper return wrapped(*args, **kwargs) File "C:\Users\tdi5539\Anaconda3\lib\site-packages\googleapiclient\http.py", line 935, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: <HttpError 404 when requesting https://chat.googleapis.com/v1/spaces/AAAAcE3QeHo/messages?alt=json returned "Invalid project number.". Details: "Invalid project number.">

Could anyone explain for me what is the problem?

Here is my code by the way:

from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
scopes = 'https://www.googleapis.com/auth/chat.bot'
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'credentials.json', scopes)
chat = build('chat', 'v1', http=credentials.authorize(Http()))
resp = chat.spaces().messages().create(
    parent='spaces/AAAAcE3QeHo', # use your space here
    body={'text': 'Test message'}).execute()
print(resp)
2
  • How did you come up with the file credentials.json? Can you check whether you can access the corresponding GCP project? Commented Jul 15, 2021 at 8:55
  • 1
    Hi @Sakshi Gatyan, were you able to find out the root cause. I'm also facing the same issue, which shows "invalid project number" after making the API call Commented Aug 2, 2021 at 22:07

2 Answers 2

0

You need to setup your Bot, and you can only setup Bots using Google Workspace aka GSuite accounts

In my case I started the project with a @gmail.com account and had to add a user from Google Workspace @mycompany.com to the project and setup the Bot from that account.

Link to setup Google Chat Bots should be something like: https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat?authuser=1&project=[your-project]&supportedpurview=project

Sign up to request clarification or add additional context in comments.

Comments

0

in my case I had to use option.WithQuotaProject in golang, probably quota_project_id in python according to this page

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.