Messenger API获取用户位置求助:Location Quick Reply在API4.0已废弃
解决Messenger API 4.0+获取用户位置的问题
问题根源
你碰到的报错是因为API 4.0及以上版本已彻底弃用content_type: "location"类型的快速回复,必须使用官方指定的替代方案。
正确请求示例
改用请求用户位置按钮实现位置获取,以下是完整请求JSON:
{ "recipient": { "id": "userid" }, "message": { "attachment": { "type": "template", "payload": { "template_type": "button", "text": "To assist you better, could you please share your location?", "buttons": [ { "type": "request_user_location", "title": "Share My Location" } ] } } } }
关键说明
- 按钮必须包含
title字段,用于在聊天界面显示按钮文本 - 用户点击按钮后,会触发系统原生的位置授权弹窗,授权成功后,Messenger会通过webhook将位置数据推送给你的服务
- 位置数据会包含在
message.attachments数组中,具体坐标信息在attachments[0].payload.coordinates字段(包含lat和long)
内容的提问来源于stack exchange,提问作者Achraf Chrouda
相关产品推荐
相关产品推荐

