如何在python的Slack API中使用参数?

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

我正在尝试使用python来获取所有处于松弛状态的用户的列表。使用users.list可以使我获得前1000个用户。为了得到其余的信息,我需要传递一个游标值。当我在其网站上使用slack自己的测试器时,Cursor值起作用。

users.list方法返回1000条记录,如果我使用游标变量(在slack dev网站中测试url调用),则每次调用都会给我带来另外一千个用户。

这是我现在用来获取用户列表的代码:

client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
request=client.api_call("users.list")

根据松弛documentation users.list具有一个称为游标的可选参数,用于获取下一个10000个用户。但是我不知道如何将光标变量与users.list命令一起传递。我查看了堆栈溢出情况,以了解其他人如何使用users.list,但无法获得该实例的任何实例。

python slack slack-api
2个回答
0
投票
Create a request and execute the API call to Slack. Args: api_method (str): The target Slack API method. e.g. 'chat.postMessage' http_verb (str): HTTP Verb. e.g. 'POST' files (dict): Files to multipart upload. e.g. {imageORfile: file_objectORfile_path} data: The body to attach to the request. If a dictionary is provided, form-encoding will take place. e.g. {'key1': 'value1', 'key2': 'value2'} params (dict): The URL parameters to append to the URL. e.g. {'key1': 'value1', 'key2': 'value2'} json (dict): JSON for the body to attach to the request (if files or data is not specified). e.g. {'key1': 'value1', 'key2': 'value2'}

由于接受的内容类型是application / x-www-form-urlencoded,我们必须使用'

data'

client = slack.WebClient(token=os.environ['SLACK_API_TOKEN']) request=client.api_call("users.list", data={'cursor': 'dXNlcjpVMDYxTkZUVDI='})


0
投票
client = slack.WebClient(token=os.environ['SLACK_API_TOKEN']) request=client.api_call("users.list") while True: if request['response_metadata']: if 'next_cursor' in request['response_metadata']: request = client.api_call("users.list" , data={'cursor':request['response_metadata']['next_cursor']}) else: break
© www.soinside.com 2019 - 2024. All rights reserved.