通过 python 为给定的工作空间创建批量松弛通道

问题描述 投票:0回答:0

我正在执行一项任务,在 slack 工作区(slack 的付费版本)中创建数百个频道。

我已经从 https://api.slack.com/authentication/token-types 创建了一个“配置令牌”,我正在使用以下代码:

#!/usr/bin/env python

import os
from time import time

import pandas as pd
from slack import WebClient

api = "xoxe.xoxp-1-Token"  #Obviously this is not the real token
df = pd.read_excel("Channel_list.xlsx")
#  print(df.columns)
#cname = (df["Slack_Channel_Name"].values[:200])
#print(cname[0])
client = WebClient(token=api)
#channel_name = cname[0]
channel_name="Trial"
response = client.conversations_create(name=channel_name)
channel_id = response["channel"]["id"]
response = client.conversations_archive(channel=channel_id)

我收到错误:

 Traceback (most recent call last):
  File "/home/rudra/Documents/Office/ICONN2023/Poster/slack_channel.py", line 16, in <module>
    response = client.conversations_create(name=channel_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rudra/.local/lib/python3.11/site-packages/slack/web/client.py", line 1160, in conversations_create
    return self.api_call("conversations.create", json=kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rudra/.local/lib/python3.11/site-packages/slack/web/base_client.py", line 150, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rudra/.local/lib/python3.11/site-packages/slack/web/base_client.py", line 241, in _sync_send
    return self._urllib_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rudra/.local/lib/python3.11/site-packages/slack/web/base_client.py", line 378, in _urllib_api_call
    ).validate()
      ^^^^^^^^^^
  File "/home/rudra/.local/lib/python3.11/site-packages/slack/web/slack_response.py", line 194, in validate
    raise e.SlackApiError(message=msg, response=self)
slack.errors.SlackApiError: The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'missing_scope', 'needed': 'channels:write,groups:write,mpim:write,im:write', 'provided': 'identify,app_configurations:read,app_configurations:write'}
python slack-api
© www.soinside.com 2019 - 2024. All rights reserved.