我正在尝试使用 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
呢?
先决条件:
更新照片资料:
- 调用
POST https://graph.facebook.com/v14.0/{{appId}}/uploads?access_token={{token}}&file_length={{fileSizeInByte}}&file_type=image/jpeg
- 保存您获得的 session ID,
upload:XXXXXX?sig=XXXXXX
。 - 调用
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,请参见下图(这是我错过了几个小时的内容)。 - 保存你得到的句柄结果,
4::XXX==:XXXXXX
。 - 最后,使用 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/