Google Chat Rest API

huangapple go评论71阅读模式
英文:

Google Chat Rest API

问题

I have not been able to find any documentation to authenticate and use the Google Chat API using a simple REST request.
我尚未找到任何关于使用简单的REST请求进行Google Chat API身份验证和使用的文档。

I have scoured the Google official documentation and it immediately states we must use Python.
我已仔细查阅Google官方文档,它立即指出我们必须使用Python。

As far as I know REST is simply HTTP and JSON.
据我所知,REST只是HTTP和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
官方文档 链接将示例引用到Google Drive和Google Plus(已弃用)。我不是Google API的新手,已成功为Drive、Sheets、Calendar和Maps编程。这个聊天是我请求帮助的地方。

Any help / further documentation links is all I ask !!!
我只是请求任何帮助/进一步的文档链接!!!

I am asking for documentation/examples of REST request (with auth) and methods and parameters
我正在请求REST请求(带有身份验证)以及方法和参数的文档/示例。

I am programming in PHP.
我正在使用PHP编程。

英文:

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.

答案1

得分: 3

我不确定您指的是哪个文档,但我还没有找到任何明确说明我们必须使用Python的文档。可能是因为其他语言的示例代码不够丰富。不过,Google已经为各种流行的编程语言开发了客户端库。对于PHP,您可以使用google-api-php-client库,该库在官方文档2中有提到。

以下是发送消息的示例代码,我成功地使用我的凭据和聊天空间尝试过它:

$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);

您可以查看Google Chat可用的类和方法在这里

英文:

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

huangapple
  • 本文由 发表于 2023年5月30日 07:32:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360820.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定