我试图通过Whatsapp API发送图像,但失败。我上传了一张图片,有媒体ID,可以用curl下载。甚至一个图像链接也不工作-我没有得到任何错误,事实上,响应看起来完全没问题!这是我尝试的;
尝试将图像作为ID为的上传媒体发送
curl -X POST
'https://graph.facebook.com/v15.0/XXX/messages'
-H 'Authorization: Bearer XXX'
-H 'Content-Type: application/json'
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "XXX",
"type": "image",
"image": {"id" : "XXX"}
}'
# response:
# {"messaging_product":"whatsapp","contacts":[{"input":"XXX","wa_id":"XXX"}],"messages":[{"id":"wamid.XXX"}]}
尝试将图像作为链接发送
curl -X POST 'https://graph.facebook.com/v13.0/SENDER/messages'
-H 'Authorization: Bearer XXX'
-H 'Content-Type: application/json'
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "XXX",
"type": "image",
"image": { "link" : "https://placekitten.com/500/500" }
}'
# response:
# {"messaging_product":"whatsapp","contacts":[{"input":"XXX","wa_id":"XXX"}],"messages":[{"id":"wamid.XXX}]}
两个看起来都不错,但我实际上什么也没收到。当我使用消息模板发送时,它立即工作良好。
两天后,我的请求突然开始生效,我没有做任何改变。似乎我的帐户或项目或其他东西可能处于某种验证周期,不允许发送媒体。