api - Whatsapp Cloud API 更新头像

标签 api postman cloud whatsapp

我正在尝试使用 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.

阅读文档并导入后Postman Endpoints我找到了名为 Business Profiles > Update Business Profile

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

它有一个字段“profile_picture_url”我试过发布媒体https://graph.facebook.com/{{Version}}/{{Phone-Number-ID} }/media 然后使用给定的 ID y 使用 https://graph.facebook.com/{{Version}}/{{Media-ID}} 获取 URL 但是它没有用。其余信息更新成功

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

但是,如果我尝试使用 ID 和端点发送给某人 https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/messages它工作正常。 如果我在 Postman 中使用带有 URL 的下载媒体内容,它也能正常工作。

不知道是不是我理解错了什么,还是不能用API来完成。

最佳答案

它在 Cloud API Documentation 中提到:

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

但是,我使用 profile_picture_handle 而不是 profile_picture_url 让它工作。那么我们如何获得profile_picture_handle呢?

先决条件:

  1. 图形 API token here .或者使用您的 WhatsApp Cloud API token 。
  2. 应用 ID,转到 Apps > 您的应用 > 设置(侧边栏菜单)> 基本

更新照片资料:

  1. 调用 POST https://graph.facebook.com/v14.0/{{appId}}/uploads?access_token={{token}}&file_length={{fileSizeInByte}}&file_type=image/jpeg
  2. 保存您获得的 session ID,upload:XXXXXX?sig=XXXXXX
  3. 调用 POST https://graph.facebook.com/v14.0/{{sessionId}}, header :Authorization=OAuth {{token}}, file_offset= 0,Host=graph.facebook.com,Connection=close,Content-Type=multipart/form-data,并在请求正文中包含您的图像文件,类型为二进制。如果您使用 Postman,请参见下图(这是我错过了几个小时的内容)。 enter image description here
  4. 保存你得到的句柄结果,4::XXX==:XXXXXX
  5. 最后,使用 json 请求正文调用 POST https://graph.facebook.com/{{Version}}/{{Phone-Number-ID}}/whatsapp_business_profile: {"messaging_product": "whatsapp", "profile_picture_handle": "4::XXX==:XXXXXX"}

就是这样,您可以查看头像。

关于api - Whatsapp Cloud API 更新头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72479849/

相关文章:

java - 如何自动上传数据到Google云存储

javascript - 解析云代码关系查询

java在reterofit 2 api调用中找不到局部变量

c# - 如何从 Postman 获取表单数据到 WebApi

amazon-web-services - 使用 Cognito 您的用户池用户使用 Postman 签署 AWS 请求

python-3.x - Python HTTPServer 响应 curl 但不响应 Postman GET 请求

mysql - 了解 Docker 以提供 web、mysql 或类似服务

java - 使用 google Sheets api java 根据列对范围进行排序

python - 使用 python wikitools 解析维基百科 stub

ios - 在SWIFT中解析JSON API到WIFI和4G的不同结果