1

I have not been able to find any documentation to authenticate and use the Google Chat API using a simple REST request. I have scoured the Google official documentation and it immediately states we must use Python. As far as I know REST is simply HTTP and JSON.

The official documention link refers examples to Google Drive and Google Plus (deprecated). I am not a novice at Google APIs and have successfully programmed for Drive, Sheets, Calendar and Maps. This Chat is where I am requesting help

Any help / further documentation links is all I ask !!!

I am asking for documentation/examples of REST request (with auth) and methods and parameters

I am programming in PHP.

Datadimension
  • 872
  • 1
  • 12
  • 31

1 Answers1

3

I'm not sure which documentation you are referring to, but I haven't come across any documentation that explicitly states that we must use Python. It's possible that there is a lack of example code for other languages. However, Google has developed client libraries for various popular languages. For PHP, you can utilize the google-api-php-client library, which is mentioned in their official documentation.

Here the example code to send a message. I successfully tried it using my credential and chat space.

    $client = new Client();
    $client->setAuthConfig('/path/to/client_credentials.json');
    $client->addScope('https://www.googleapis.com/auth/chat.bot');
    $chat = new Google\Service\HangoutsChat($client);
    $message = new \Google\Service\HangoutsChat\Message();
    $message->setText("This is example message");
    $createMessage = $chat->spaces_messages->create('spaces/AAAAqFtzdps',$message);

You can check the available class/methods of google chat here

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
  • I read that and exactly my point, the official documention link refers examples to Google Drive and Google Plus (deprecated). I am not a novice at Google APIs and have successfully programmed for Drive, Sheets, Calendar and Maps. This Chat is where I am requesting help – Datadimension May 30 '23 at 00:16
  • 1
    Google drive is just an example, you can use other service also like Chat, Books, and other. I will provide you an example for chat. – Muhammad Dyas Yaskur May 30 '23 at 00:20
  • Thanks, exactly what I am asking for, REST request (with auth) and documentation on methods and parameters – Datadimension May 30 '23 at 00:23
  • thanks @Muhammad Dyas Yaskur I will try it out - is this for the current Chat App and not old Hangouts - I ask as I see $client->addScope('https://www.googleapis.com/auth/chat.bot'); $chat = new Google\Service\HangoutsChat($client); – Datadimension May 30 '23 at 00:48
  • @Datadimension old hangout is upgraded to current chat app. So this is for current chat app. BTW, If you are interested for your reference, I also built couple of google chat apps using nodejs: https://github.com/dyaskur/google-chat-poll . I also have a plan to build app using PHP and other languages in the future. – Muhammad Dyas Yaskur May 30 '23 at 00:53
  • Sounds like great work. I think lacking particularly with Google is that they state they use REST and then all the examples, much of their docs start with PREREQUITES - Python ????? I would have thought REST would be their basis to work from but oh well. A pure REST API for all their APIs would be magnificent..... :) – Datadimension May 30 '23 at 01:00
  • 1
    It's just not feasible to provide reference docs for every API in every language. They don't even write the client libraries, it's all generated code. For all but the prestige-tier Google services you're going to need to get cozy with the API docs and reading the client library source. – Sammitch May 30 '23 at 01:29
  • Google\Service\Exception { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { "message": "The request is missing a valid API key.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } } – Datadimension May 30 '23 at 18:06