简体   繁体   English

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

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

I created Slack app, added Bot and Incoming Webhook to it and posted some messages with Bot.我创建了 Slack 应用程序,向其中添加了 Bot 和 Incoming Webhook,并使用 Bot 发布了一些消息。 Now I would like to find out time stamp of Slack message in order to delete it later with chat.delete method.现在我想找出 Slack 消息的时间戳,以便稍后使用chat.delete方法将其删除。

I found it that I can use channels.history method.我发现我可以使用channels.history方法。

Here is how I tried to use it.这是我尝试使用它的方式。 I used it with token found under OAuth Access Token, since per docs I cannot use Bot token with channels.history method.我将它与 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")

I got back the following error:我得到以下错误:

{'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'}

If this is permission issue, how do I find out proper token to use?如果这是权限问题,我如何找到要使用的正确令牌?

According to the error message you posted the token used is lacking the required scope.根据您发布的错误消息,使用的令牌缺少所需的范围。

'needed': 'channels:history' '需要':'频道:历史'

It looks like you provided the bot token, which can not work.看起来您提供了无法工作的机器人令牌。

'provided': 'identify,bot,incoming-webhook' '提供':'识别,机器人,传入网络钩子'

Provide the access token and make sure you first add the channel.history scope and reinstall the app to activate.提供访问令牌并确保首先添加channel.history范围并重新安装应用程序以激活。

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

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