简体   繁体   English

Whatsapp Cloud API 更新资料图片

[英]Whatsapp Cloud API Update Profile Picture

I'm trying to upload an image as profile picture using WhatsApp Cloud API *.我正在尝试使用 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.使用 WhatsApp Cloud API 创建应用程序后,我既不能使用常规应用程序也不能使用业务应用程序访问。 It says something like "try again in one hour".它说类似“一小时后再试”。 So I have to implement everything using the API.所以我必须使用 API 来实现一切。

After reading the docs and importing Postman Endpoints I found the one called Business Profiles > Update Business Profile阅读文档并导入Postman 端点后,我找到了一个名为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. 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}}以获取 URL 但它不起作用。 The rest of the information is updated successfully信息的rest更新成功

{
    "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.但是,如果我尝试使用 ID 和端点https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/messages发送某人,它工作正常。 And if I use Download Media Content with the URL in Postman it works fine too.如果我使用 Postman 中的 URL下载媒体内容,它也可以正常工作。

I don't know if I have misunderstood something or if it can't be done using the API.我不知道我是否误解了某些内容,或者使用 API 是否无法完成。

It is mentioned in the Cloud API Documentation : Cloud API 文档中提到了它:

profile_picture_url (Optional): URL of the profile picture generated from a call to the Resumable Upload API . profile_picture_url (可选):通过调用Resumable Upload API生成的个人资料图片的 URL。

But, i got it working using profile_picture_handle instead of profile_picture_url .但是,我使用profile_picture_handle而不是profile_picture_url让它工作。 So how do we get the profile_picture_handle ?那么我们如何获得profile_picture_handle呢?

Prerequisite:先决条件:

  1. Graph API token here .在此处绘制 API 令牌。 Or use your WhatsApp Cloud API token.或使用您的 WhatsApp Cloud API 令牌。
  2. App ID, go Apps > Your App > Settings (sidebar menu) > Basic应用 ID,转到应用> 您的应用 > 设置(侧边栏菜单)> 基本

Update Photo Profile:更新照片资料:

  1. Call POST https://graph.facebook.com/v14.0/{{appId}}/uploads?access_token={{token}}&file_length={{fileSizeInByte}}&file_type=image/jpeg调用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 .保存你得到的会话 id, 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.调用POST https://graph.facebook.com/v14.0/{{sessionId}} ,标题为: Authorization=OAuth {{token}}, file_offset=0, Host=graph.facebook.com, Connection=close, Content-Type=multipart/form-data ,并将您的图像文件包含在二进制类型的请求正文中。 If you using Postman, see image below (This is what I missed for hours).如果您使用 Postman,请参见下图(这是我错过了几个小时的内容)。 在此处输入图像描述
  4. Save the handle result you got, 4::XXX==:XXXXXX .保存你得到的句柄结果, 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"}最后,调用POST https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile请求正文: {"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.最后一步,您必须通过选择“Bearer”添加您的拍摄,否则它会给您带来错误。 I had hard time on the last ones, do all the steps and then go to the following link and it should help.我在最后一个方面遇到了困难,完成所有步骤,然后 go 到以下链接,它应该会有所帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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