使用WhatsApp Cloud API发送图像
我正在尝试使用 whatsapp cloud cloud api api < /a>。使用PHP,我能够成功发送普通短信。
通过文档,' Media_object_id '是什么意思?一个例子很棒。
curl -X POST \
'https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "PHONE_NUMBER",
"type": "image",
"image": {
"id" : "MEDIA_OBJECT_ID"
}
}'
谢谢
I am trying to send images with Whatsapp Cloud API. Using PHP, I am able to send normal text messages successfully.
When going through the docs, what does 'MEDIA_OBJECT_ID' mean ? An example would be great.
curl -X POST \
'https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages' \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "PHONE_NUMBER",
"type": "image",
"image": {
"id" : "MEDIA_OBJECT_ID"
}
}'
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
首先,您需要将媒体文件上传到WhatsApp服务器,然后WhatsApp现在将响应Media_object_id
,您将获得媒体对象ID。您需要从API发送媒体
是不同类型的媒体JSON
First, you need to upload the media file to the WhatsApp Server then WhatsApp will respond back the MEDIA_OBJECT_ID
Now, you will get the media object id. You need to send the media from API
Here is the different type of media JSON
您需要将媒体上传到 https://graph.face.face.com/v13.03.03.03.03.03.0 /from_phone_number_id/媒体
响应将为您提供“ Media_object_id”
或
使用映像链接
You need to upload the media to https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/media
The response will give you the "MEDIA_OBJECT_ID"
OR
use image link instead
媒体消息
要发送媒体消息,请向/phone_number_id/sagess发送帖子,然后使用 type = image,文档,音频,图像,视频或贴纸附加消息对象。然后,添加一个相应的媒体对象。
使用图像与链接的示例请求:
发布
url 发送图像消息
要发送媒体消息,请向 /{{{phone-number-id}} /消息进行帖子调用,然后将消息对象连接到type = image。然后,请确保包括图像的链接。
使用指向图像文件的链接向客户发送音频消息。
授权:承载令牌的
身体
{
“ Messaging_product”:“ WhatsApp”,
“ conferient_type”:“个人”,
“ to”:“ {{{cocceent-phone-number}}”,
“类型”:“图像”,
“图像”: {
“链接”:“ http(s):// image-url”
}
}
php卷曲的示例
&lt;?php
响应:
https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages-media-messages
Media Messages
To send a media message, make a POST call to /PHONE_NUMBER_ID/messages and attach a message object with type=image, document, audio, image, video, or sticker. Then, add a corresponding media object.
Sample request using image with link:
POST
Send Image Message by URL
To send a media message, make a POST call to /{{Phone-Number-ID}}/messages and attach a message object with type = image. Then, be sure to include the link to the image.
Send an audio message to your customers using a link to an image file.
Authorization : Bearer Token
BODY
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "{{Recipient-Phone-Number}}",
"type": "image",
"image": {
"link": "http(s)://image-url"
}
}
example in PHP CURL
<?php
RESPONSE:
https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages#media-messages
使用Postman
URL:
对象:
不要忘记...
一些Web服务器不允许访问文件...
Example using Postman
URL:
OBJECT:
Don't forget...
Some web server does not permit access to files...????
我建议您从您的开发人员dashboard下载WhatsApp Cloud API Postman Collection以后的疑问:
在左侧栏中,转到WhatsApp -&gt;入门
单击按钮“在Postman中运行”以打开完整的API示例集合
,以便您建议您安装 php sdk for whatsapp cloud api:
I recommend you to download the WhatsApp Cloud API Postman collection from you Developer Dashboard for future doubts:
In left sidebar, go to WhatsApp -> Getting Started
Click on the button "Run in Postman" to open a full API collection of samples
By the way I recommend you install the PHP SDK for WhatsApp Cloud API:
@apositivo,将上述代码放在邮递员上时,我得到了wamid。#######。但是我没有收到媒体消息?有什么特别的原因吗?还是我应该使用媒体对象ID?
{
“ Messaging_product”:“ WhatsApp”,
“ conferient_type”:“个人”,
“ to”:“ {{{cocceent-phone-number}}”,
“类型”:“图像”,
“图像”: {
“链接”:“ https://iprovider.pk/whatsappapi/1640191015925.jpg”
}
}
@apositivo, when putting the above code on postmen, i got the wamid.#######. but I didn't receive the media message? any particular reason? or should i use the media object id?
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "{{Recipient-Phone-Number}}",
"type": "image",
"image": {
"link": "https://iprovider.pk/whatsappapi/1640191015925.jpg"
}
}
有两种方法可以通过
链接
或ID
上传媒体。要获取
ID
或链接
首先,您需要使用API上传媒体,该API将返回媒体对象,并使用ID
链接。我使用了 whatsapp ruby sdk 与API连接,看起来像这样:
there are two ways to upload a media via
link
or anid
.To get an
id
or alink
first you need to upload the media using the API which would return a media object withID
and alink
.I used the Whatsapp Ruby SDK for connecting with the API which looks like this: