如何在Google环聊聊天中删除Webhook发送的消息

时间:2019-05-28 08:41:12

标签: hangouts-chat hangouts-api

我跟随incoming bot python发送了带有Webhook的消息,并想通过Method:delete删除它。

但是我收到错误401,以下是错误消息。

{'error': {'code': 401,
           'message': 'Request is missing required authentication credential. '
                      'Expected OAuth 2 access token, login cookie or other '
                      'valid authentication credential. See '
                      'https://developers.google.com/identity/sign-in/web/devconsole-project.',
           'status': 'UNAUTHENTICATED'}}

Webhook似乎使用密钥和令牌作为授权。但是我无法删除具有相同网址(目标为“ data-id”)的邮件。

2 个答案:

答案 0 :(得分:0)

您必须已经下载了凭证文件。如果不是,则按照this

下载后,请按照以下步骤生成Auth令牌。

  1. 设置环境变量

    导出GOOGLE_APPLICATION_CREDENTIALS =

  2. 在终端上运行此命令。

    gcloud auth应用程序-默认打印访问令牌

  3. 在邮递员中使用生成的令牌->授权->键入OAuth 2.0->访问令牌 要么 在标头中为

    标题= { “ Content-Type”:“ application / json”, '授权':“承载者”, ... }

答案 1 :(得分:0)

无法删除Google环聊中通过Webhook发送的消息,或者至少尚未建立该功能。

如果您是通过项目本身的Appscript代码本身(不使用Webhook,即通过spaces.messages.create)将消息发布到房间中或向某人发送DM,则可以使用此方法{{1 }}(选中here

如果尝试使用上述方法(spaces.messages.delete)删除使用Webhook发布的消息,则将出现以下错误

spaces.messages.delete

这是因为您要删除的消息是由Webhook发布的,而不是通过应用程序代码库或使用{ "error": { "code": 403, "message": "Request had insufficient authentication scopes.", "status": "PERMISSION_DENIED" } } 发布的,因此生成的访问令牌没有权限删除消息,因为它属于到appscript项目而不是webhook机器人。

希望能解决您的问题!