我正在尝试使用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。
关于python - 如何通过python slackclient将application/x-www-form-urlencoded发送到slack?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56994503/