繁体   English   中英

从 Python API 中找出 Slack 消息的时间戳

[英]Find out time stamp of Slack message from Python API

我创建了 Slack 应用程序,向其中添加了 Bot 和 Incoming Webhook,并使用 Bot 发布了一些消息。 现在我想找出 Slack 消息的时间戳,以便稍后使用chat.delete方法将其删除。

我发现我可以使用channels.history方法。

这是我尝试使用它的方式。 我将它与 OAuth 访问令牌下的令牌一起使用,因为根据文档我不能将 Bot 令牌与channels.history方法一起使用。

from slackclient import SlackClient
slack_token_user_token = 'xoxp-long_string_of_integers'
sc_user_token = SlackClient(slack_token_user_token)

sc_user_token.api_call(
    "channels.history",
  channel="CHXXXXXXX")

我得到以下错误:

{'error': 'missing_scope',
 'headers': {'Access-Control-Allow-Headers': 'slack-route, x-slack-version-ts',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Expose-Headers': 'x-slack-req-id',
  'Cache-Control': 'private, no-cache, no-store, must-revalidate',
  'Connection': 'keep-alive',
  'Content-Encoding': 'gzip',
  'Content-Length': '108',
  'Content-Type': 'application/json; charset=utf-8',
  'Date': 'Fri, 05 Apr 2019 18:18:11 GMT',
  'Expires': 'Mon, 26 Jul 1997 05:00:00 GMT',
  'Pragma': 'no-cache',
  'Referrer-Policy': 'no-referrer',
  'Server': 'Apache',
  'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload',
  'Vary': 'Accept-Encoding',
  'Via': '1.1 f0f1092b2ad1f0e573a4fcbefe4fb621.cloudfront.net (CloudFront)',
  'X-Accepted-OAuth-Scopes': 'channels:history',
  'X-Amz-Cf-Id': 'fSm6uo2H88E43JCvqd2h5mohnzA6z0B3kmdsG3u9nW0PJNrsrpK7mg==',
  'X-Cache': 'Miss from cloudfront',
  'X-Content-Type-Options': 'nosniff',
  'X-OAuth-Scopes': 'identify,bot,incoming-webhook',
  'X-Slack-Req-Id': 'c158668d-ddc9-4bbc-9a7d-6b9a9011d2dc',
  'X-Via': 'haproxy-www-yfr6',
  'X-XSS-Protection': '0'},
 'needed': 'channels:history',
 'ok': False,
 'provided': 'identify,bot,incoming-webhook'}

如果这是权限问题,我如何找到要使用的正确令牌?

根据您发布的错误消息,使用的令牌缺少所需的范围。

'需要':'频道:历史'

看起来您提供了无法工作的机器人令牌。

'提供':'识别,机器人,传入网络钩子'

提供访问令牌并确保首先添加channel.history范围并重新安装应用程序以激活。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM