如何通过python slackclient将application/xwwformurlencoded发送到slack?

2024-03-29 15:35:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用api调用users.profile.get来查找用户配置文件图片。问题是请求不需要JSON,而需要URL编码的查询(我认为是?)。我已经有了用户id,但是我需要知道如何正确地将它发送到slack,最好使用api_call方法。怎么做我会同意这样做吗?你知道吗

以下是文档:https://api.slack.com/methods/users.profile.get

for users in collection.find():
                start_date, end_date = users['start_date'], users['end_date']

                user_data = client.api_call('users.profile.get',
                                            """What would I do here?""")
                user_images[users['user_id']] = user_data['image_72']
                block.section(
                    text=
                    f'from *{date_to_words(start_date[0], start_date[1], start_date[2])}* to *{date_to_words(end_date[0], end_date[1], end_date[2])}*'
                )
                block.context(data=((
                    'img', user_images[users['user_id']],
                    '_error displaying image_'
                ), ('text',
                    f'<!{users["user_id"]}>. _Contact them if you have any concerns_'
                    )))

Tags: to用户apiiddatagetdatecall
1条回答
网友
1楼 · 发布于 2024-03-29 15:35:53

在函数调用中,可以将API的参数作为names参数传递。你知道吗

为了users.get.profile文件您需要提供用户ID,例如“U1245678”。你知道吗

然后您的调用将如下所示(使用slackclient v1):

response = sc.api_call(
  "users.profile.get",  
  user="U12345678"
)
assert response["ok"]
user_data = response["profile"]

或者类似于slackclient v2:

response = sc.users_profile_get(user="U12345678")
assert response["ok"]
user_data = response["profile"]

回答您的问题:您不必担心如何调用API,因为这是由库处理的。但从技术上讲,大多数Slack的API端点都接受URL格式和JSON格式的参数。你知道吗

相关问题 更多 >