微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何配置仅对公共频道具有只读访问权限的 Slack API OAuth 令牌?

如何解决如何配置仅对公共频道具有只读访问权限的 Slack API OAuth 令牌?

(此处为 Slack API n00b)

我正在尝试使用 Slack API 在我们的一些公共 Slack 频道(我们组织内部)中搜索消息。

我通过 Python SDK 使用 https://www.slack.com/api/search.messages API,这意味着我正在执行以下操作:

import logging
from slack_sdk import WebClient
from pprint import pprint
    
    
def main():
    logging.basicConfig(level=logging.INFO)

    # TOKEN:
    t = 'xoxp-***'

    print("Getting client")
    c = WebClient(token=t)
    response = c.search_messages(query='in:#some_public_channel some-search-string')
    print("Response Code: {}".format(response.status_code))
    print("Found {} messages.".format(len(response.data['messages']['matches'])))
    
if __name__ == '__main__':
    main()

如果我使用“用户 OAuth 令牌”,我只能使上面的代码正常工作,不幸的是,该令牌也可以访问与该用户相关的所有私人消息。

我想要一个只能通过公共渠道搜索的 OAuth 令牌(只读)。通过这种方式,它可以在同一团队的成员之间共享(例如)。

有什么建议可以解决这个问题吗?

背景信息:

  1. 如果我尝试使用“机器人用户身份验证令牌”,我会收到 not_allowed_token_type 错误
DEBUG:slack_sdk.web.slack_response: Received the following response - 
status: 200,headers: {...},body: {'ok': False,'error': 'not_allowed_token_type'}
  1. 我使用的令牌是通过我专门为此目的而创建的“应用程序”生成的:

enter image description here

解决方法

只有用户才能访问 search.messages API,机器人不能访问。我可以建议的最佳解决方法是 -

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。