如何在 Slack API 和 python 中使用参数?
How to use arguments in Slack API with python?
我正在尝试使用 python 获取 slack 上所有用户的列表。使用 users.list
获得前 1000 个用户。为了获得其余部分,我需要传入一个游标值。当我在其网站上使用 slack 自己的测试器时,光标值有效。
users.list
方法 returns 1000 条记录,如果我使用游标变量(在 slack dev 网站上测试 url 调用),每次调用都会给我另外一千个用户。
这是我现在用来获取用户列表的代码:
client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
request=client.api_call("users.list")
根据 slack documentation users.list
有一个名为 cursor 的可选参数来获取接下来的 10000 个用户。但是我不知道如何将游标变量与 users.list 命令一起传递。我查看了堆栈溢出以了解其他人如何使用 users.list 但我无法获得任何实例。
https://github.com/slackapi/python-slackclient/blob/master/slack/web/base_client.py#L97
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='})
我来帮你吧。
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
我对此很确定,因为我最近使用 python sdk 与 odoo 进行了松散集成。可能需要一些改变
我正在尝试使用 python 获取 slack 上所有用户的列表。使用 users.list
获得前 1000 个用户。为了获得其余部分,我需要传入一个游标值。当我在其网站上使用 slack 自己的测试器时,光标值有效。
users.list
方法 returns 1000 条记录,如果我使用游标变量(在 slack dev 网站上测试 url 调用),每次调用都会给我另外一千个用户。
这是我现在用来获取用户列表的代码:
client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
request=client.api_call("users.list")
根据 slack documentation users.list
有一个名为 cursor 的可选参数来获取接下来的 10000 个用户。但是我不知道如何将游标变量与 users.list 命令一起传递。我查看了堆栈溢出以了解其他人如何使用 users.list 但我无法获得任何实例。
https://github.com/slackapi/python-slackclient/blob/master/slack/web/base_client.py#L97
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='})
我来帮你吧。
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
我对此很确定,因为我最近使用 python sdk 与 odoo 进行了松散集成。可能需要一些改变