![](/img/trans.png)
[英]how to send application/x-www-form-urlencoded JSON string in python botlle server
[英]How to send application/x-www-form-urlencoded to slack via python slackclient?
我正在尝试使用 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_'
)))
您可以在函数调用中将 API 的参数作为名称参数传递。
对于 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 形式的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.