【发布时间】:2019-04-05 17:17:32
【问题描述】:
我正在按照以下教程 Slack API tutorial 在 slack 上发布消息。我已经创建了 Slack 应用程序,并且能够将它与 Incoming Webhooks 一起使用,现在我想使用来自 python 的 API。所以我尝试了:
import os
from slackclient import SlackClient
slack_token = 'xoxp-long-sequence-of-numbers'
sc = SlackClient(slack_token)
sc.api_call(
"chat.postMessage",
channel="my_test_channel",
text="Hello from Python! :tada:"
)
我收到以下错误消息:
{'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': '105',
'Content-Type': 'application/json; charset=utf-8',
'Date': 'Fri, 05 Apr 2019 17:07:06 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 6529456e34a07353ab1987432f192696.cloudfront.net (CloudFront)',
'X-Accepted-OAuth-Scopes': 'chat:write:user',
'X-Amz-Cf-Id': 'wunHQVQpZicf-ynJO2u_n6CAQEGlYBH67ysu0fP1mfTEt86rRiAbrw==',
'X-Cache': 'Miss from cloudfront',
'X-Content-Type-Options': 'nosniff',
'X-OAuth-Scopes': 'identify,incoming-webhook',
'X-Slack-Req-Id': '990760fb-b110-43a1-86cb-fd4f8e2e34fa',
'X-Via': 'haproxy-www-km3w',
'X-XSS-Protection': '0'},
'needed': 'chat:write:user',
'ok': False,
'provided': 'identify,incoming-webhook'}
我的频道名称实际上是:my_test_channel。可能我需要使用不同的名称,但我怎样才能找到它?
更新
所以我找到了编码的频道 ID 并将我的脚本更改为:
import os
from slackclient import SlackClient
slack_token = 'xoxp-long-sequence-of-numbers'
sc = SlackClient(slack_token)
sc.api_call(
"chat.postMessage",
channel="CHXXXXXXX",
text="Hello from Python! :tada:"
)
但错误返回仍然是missing scope
【问题讨论】:
-
my_test_channel是私有的还是公有的? (您的 slack 或主题标签旁边是否有锁)根据我的经验,slack python api 无法与私人频道交谈 -
@RichardStoeffel。它是公开的,没有锁。有标签
#my_test_channel -
如何获得自己频道的 slack-token ?