WhatsApp location_request_message调用失败:OAuthException错误
解决WhatsApp Business API发送位置请求消息的OAuthException(错误码100)
问题详情
调用WhatsApp Business API v12.0发送位置请求消息时,收到参数验证错误:
{ "error": { "message": "(#100) Param interactive['type'] must be one of {ADDRESS_MESSAGE, BUTTON, CATALOG_MESSAGE, GALAXY_MESSAGE, LIST, MENU_OPTIONS, MESSAGE_WITH_LINK, MESSAGE_WITH_LINK_STATUS, ORDER_DETAILS, ORDER_STATUS, PRODUCT, PRODUCT_LIST} - got \"location_request_message\".", "type": "OAuthException", "code": 100, "fbtrace_id": "AgvvDCuplk_cuF-hR4oQCTD" } }
当前使用的请求Payload存在类型错误:
{ "messaging_product": "whatsapp", "recipient_type": "individual", "to": "<phone_number>", "type": "interactive", "interactive":{ "type": "location_request_message", "body": { "type": "text", "text": "Please provide your location" }, "action": { "name": "send_location" } } }
其他类型的交互式消息(按钮、列表等)均可正常发送,仅位置请求失败。
错误原因
WhatsApp Business API中,请求用户发送位置的功能属于button类型的交互式消息,并没有单独的location_request_message类型。你错误地将interactive.type设置为了API未支持的取值,触发了参数校验错误。
正确请求格式
将interactive.type改为button,并在action.buttons中添加一个type为location_request的按钮,正确的Payload如下:
{ "messaging_product": "whatsapp", "recipient_type": "individual", "to": "<phone_number>", "type": "interactive", "interactive": { "type": "button", "body": { "text": "Please provide your location" }, "action": { "buttons": [ { "type": "location_request", "location_request": { "title": "Share Location" } } ] } } }
验证步骤
- 替换Payload中的
<phone_number>为目标用户的WhatsApp号码 - 确保请求URL为
https://graph.facebook.com/v12.0/<phone_number_id>/messages,替换<phone_number_id>为你的业务号码ID - 请求头中携带有效的access token
- 发送请求后,用户端会收到带有"Share Location"按钮的消息,点击即可快速发送位置
内容的提问来源于stack exchange,提问作者Chinmoy Biswas
相关产品推荐
相关产品推荐

