1

I am trying to list the spaces of google chat by using this particular API

There are three ways to authenticate and call api

  1. Using API key
  2. Using OAuth
  3. Service account

With API Key and Service account I am getting error

curl --location 'https://chat.googleapis.com/v1/spaces?key=xxxx-xxxx-xxxx-xxxx'

{     "error": {         
"code": 401,         
"message": "API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See https://cloud.google.com/docs/authentication",         
"status": "UNAUTHENTICATED",         
"details": [            
 {                 
"@type": "type.googleapis.com/google.rpc.ErrorInfo",                 
"reason": "CREDENTIALS_MISSING",                
 "domain": "googleapis.com",                
 "metadata": {                    
 "service": "chat.googleapis.com",                     
"method": "google.chat.v1.ChatService.ListSpaces"
                 }            
 }        
 ]     
} }

On my third try I used the OAuth 2.0 Client IDs for the authentication , Like given below -

curl --location 'https://chat.googleapis.com/v1/spaces' \ --header 'Authorization: Bearer Access token of the user'

But this method is also giving me this error, even though i have enabled the chat app api from my Google Cloud console. -

{
    "error": {
        "code": 404,
        "message": "Google Chat app not found. To create a Chat app, you must turn on the Chat API and configure the app in the Google Cloud console.",
        "status": "NOT_FOUND",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.Help",
                "links": [
                    {
                        "description": "To turn on the Google Chat API, go to the Google Chat API page in the Google Cloud console and click Enable.",
                        "url": "https://console.cloud.google.com/marketplace/product/google/chat.googleapis.com"
                    }
                ]
            },
            {
                "@type": "type.googleapis.com/google.rpc.Help",
                "links": [
                    {
                        "description": "To configure your Chat app, go to the Google Chat API Configuration tab in the Google Cloud console.",
                        "url": "https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat"
                    }
                ]
            },
            {
                "@type": "type.googleapis.com/google.rpc.Help",
                "links": [
                    {
                        "description": "To learn about creating Google Chat apps, visit the documentation.",
                        "url": "https://developers.google.com/chat"
                    }
                ]
            }
        ]
    }
}

What specific thing I am missing to make api call successfully?

I am expecting to utilize key give by the Service Accounts to access the particular chat and send message into the particular chat space.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

2 Answers2

0

You need to enable the Chat API and configure it for usage. There are two steps. You can start by visiting https://console.cloud.google.com/flows/enableapi?apiid=chat.googleapis.com.

enter image description here

Justin Poehnelt
  • 2,992
  • 1
  • 19
  • 23
-1

First off api keys only access public data. Chats api is private user data.

Second chats api only works with google workspace consepts

enter image description here

third you need to enable the api in your project

Google Chat app not found. To create a Chat app, you must turn on the Chat API and configure the app in the Google Cloud console.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449