调用Slack API views.publish时view参数json-pointer错误如何解决?
问题原因
你当前的请求体结构不符合Slack views.publish 接口的要求,核心问题有两个:
- 你直接把区块配置放在了请求体根路径,没有放到要求的
view字段下 - 完整的view对象除了
blocks,还必须包含必填的type、title字段
正确配置步骤
1. 构造符合要求的view对象
view对象至少需要包含以下必填字段:
type:固定填"home"(views.publish接口专用于发布应用主页)title:标准的plain_text类型文本对象blocks:你之前编写的区块数组内容
2. 调整请求体结构
当你使用Content-Type: application/json提交请求时,请求体根层级需要包含token、user_id、view三个字段,其中view直接传对象即可,不需要额外转成字符串(JSON编码字符串的要求仅针对application/x-www-form-urlencoded类型的请求)。
正确的请求体示例:
{ "token": "你的Slack应用令牌", "user_id": "目标用户的ID", "view": { "type": "home", "title": { "type": "plain_text", "text": "应用主页" }, "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "This is a section block with a button." }, "accessory": { "type": "button", "text": { "type": "plain_text", "text": "Click Me", "emoji": true }, "value": "click_me_123", "url": "http://scoreboard-azureslackbot-salvosoftware.s3-website.us-east-2.amazonaws.com/", "action_id": "button-action" } } ] } }
3. 注意事项
- 所用令牌需要拥有对应接口权限,且支持发布应用主页的作用域
- 如果你使用form表单格式提交请求,才需要把整个view对象转成JSON字符串之后,作为view字段的值提交
内容的提问来源于stack exchange,提问作者Christopher Martinez
相关产品推荐
相关产品推荐

