我正在尝试通过 python 请求将文件上传到 Facebook 发送 API。curl发送API请求如下
curl \
-F 'recipient={"id":"<PSID>"}' \
-F 'message={"attachment":{"type":"<ASSET_TYPE>", "payload":{"is_reusable":true}}}' \
-F 'filedata=@/tmp/shirt.png;type=image/png' \
"https://graph.facebook.com/v9.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
我指的是这个 facebook 文档
我已经尝试过使用 python 请求的 API
import requests
r = requests.get('https://homepages.cae.wisc.edu/~ece533/images/us092.pgm')
with open('temp.jpg', 'wb') as f:
f.write(r.content)
files = {
'recipient': (None, '{"id":" <USER_ID>"}'),
'message': (None, '{"attachment":{"type":"image", "payload":{"is_reusable":true}}}'),
'filedata': ('temp.jpg', open('temp.jpg', 'rb')),
}
url = "https://graph.facebook.com/v9.0/me/messages"
params = {"access_token":"<ACCESS_TOKEN>"}
response = requests.post(url=url,params=params, files=files)
print(response.content)
我收到如下回复
{"error":{"message":"(#100) Upload attachment failure.","type":"OAuthException","code":100,"error_subcode":2018047,"fbtrace_id":"Atv2YqLlb4ABkoVOW4sgnzd"}}
以下是错误代码的描述
我不知道我做错了什么