简体   繁体   中英

How to get the URL of an image in WhatsApp Business Cloud API, while we send an image through WhatsApp

While working on WhatsApp Business Cloud API, I have to send an Image through WhatsApp. When I send that image I am getting a response as a sha256 base64 string and an imageId. I want to retrieve back that image using these credentials. I'm getting a url when I make a get request with that image id. That URL is actually broken/invalid and I'm not getting the image back.

Response of the request is given below:

"messages": [
              {
                "from": "918******6",
                "id": "wamid.HBgMOT*********EA",
                "timestamp": "1655978686",
                "type": "image",
                "image": {
                  "mime_type": "image/jpeg",
                  "sha256": "ian**********jM4k=",
                  "id": "4**********7"
                }
              }
            ]

if you want GET the URL of the image and download This, do you need work with the API.

in your weebhook, do you need GET the MEDIA_ID

and later with this ID_MEDIA, do you get the URL, and with this URL you can call the DOWNLOAD API and get the REAL image

All this steps, explanation and information is in the Official Documentation

https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#

and Check this very very important information

Get Media ID To complete some of the following API calls, you need to have a media ID. There are two ways to get this ID:

A successful response includes an object with a media url. The URL is only valid for 5 minutes.

From the API call: Once you have successfully uploaded media files to the API, the media ID is included in the response to your call.

From Webhooks: When a business account receives a media message, it downloads the media and uploads it to the Cloud API automatically. That event triggers the Webhooks and sends you a notification that includes the media ID.

https://i.imgur.com/bUB009c.jpg

在此处输入图像描述

if you get an invalid URL error from WhatsApp cloud API, then you should generate a new URL with the help of the media id, as the same things are described in the Download Media documentation section also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM