简体   繁体   中英

Whatsapp Cloud API Update Profile Picture

I'm trying to upload an image as profile picture using WhatsApp Cloud API *.

After creating an application using WhatsApp Cloud API I'm not allowed to access neither using the regular application nor using Business Application. It says something like "try again in one hour". So I have to implement everything using the API.

After reading the docs and importing Postman Endpoints I found the one called Business Profiles > Update Business Profile

https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile

It has a field "profile_picture_url" and I have tried POSTing media https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/media and then with the given ID y used https://graph.facebook.com/{{Version}}/{{Media-ID}} to get the URL but it didn't work. The rest of the information is updated successfully

{
    "messaging_product": "whatsapp",
    "address": "",
    "description": "Simple Bot",
    "email": "...@gmail.com",
    "websites": [
        "https://..."
    ],
    "profile_picture_url": "https://lookaside.fbsbx.com/..."
}

However if I try to send someone using the ID and the endpoint https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/messages it works fine. And if I use Download Media Content with the URL in Postman it works fine too.

I don't know if I have misunderstood something or if it can't be done using the API.

It is mentioned in the Cloud API Documentation :

profile_picture_url (Optional): URL of the profile picture generated from a call to the Resumable Upload API .

But, i got it working using profile_picture_handle instead of profile_picture_url . So how do we get the profile_picture_handle ?

Prerequisite:

  1. Graph API token here . Or use your WhatsApp Cloud API token.
  2. App ID, go Apps > Your App > Settings (sidebar menu) > Basic

Update Photo Profile:

  1. Call POST https://graph.facebook.com/v14.0/{{appId}}/uploads?access_token={{token}}&file_length={{fileSizeInByte}}&file_type=image/jpeg
  2. Save the session id you got, upload:XXXXXX?sig=XXXXXX .
  3. Call POST https://graph.facebook.com/v14.0/{{sessionId}} , with the headers: Authorization=OAuth {{token}}, file_offset=0, Host=graph.facebook.com, Connection=close, Content-Type=multipart/form-data , and include your image file in the request body with type binary. If you using Postman, see image below (This is what I missed for hours). 在此处输入图像描述
  4. Save the handle result you got, 4::XXX==:XXXXXX .
  5. Finally, call POST https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile , with json request body: {"messaging_product": "whatsapp", "profile_picture_handle": "4::XXX==:XXXXXX"}

That's it, You can check the profile picture.

The last step you have to add your taken by selecting "Bearer" or else it will give you error. I had hard time on the last ones, do all the steps and then go to the following link and it should help.

https://web.postman.co/workspace/My-Workspace~a4ddb3b8-02a3-4132-8384-66e63e149b7b/request/22958165-506a0542-c845-41ac-b3fb-b8209fd6f53b

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