我在复制第二个示例时遇到问题https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api#example_request
这是:
curl \
-F 'message={"attachment":{"type":"image", "payload":{"is_reusable":true}}}' \
-F 'filedata=@/tmp/shirt.png;type=image/png' \
"https://graph.facebook.com/v6.0/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>"
当我使用 httpbin 检查请求时,我得到:
{
"args": {},
"data": "",
"files": {
"filedata": ""
},
"form": {
"message": "{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\"=true}}}",
"recipient": "{\"id\":\"2673203139464950\"}"
},
"headers": {
"Accept": "*/*",
"Content-Length": "474",
"Content-Type": "multipart/form-data; boundary=------------------------855a2be7cb07aa99",
"Host": "httpbin.org",
"User-Agent": "curl/7.58.0",
"X-Amzn-Trace-Id": "Root=1-5e71f6ce-edeb373f3e446e443e23f2e3"
},
"json": null,
"origin": "my.ip.ad.dr",
"url": "https://httpbin.org/post"
}
当我在本地运行它时,我得到
{
"error":{
"message":"(#100) Field message must be a valid json object with string keys",
"type":"OAuthException",
"code":100,
"fbtrace_id":"ABYTTCTcFg7DoXr8i8ySdJB"
}
}
尽管付出了几天的努力,但我试图自己解决它的尝试都没有成功。我想,问题很简单,但我需要帮助。
顺便说一句,通常我需要 python-requests 将文件上传到 Facebook 的方式,因此,如果我有一个,我不需要 curl 解决方案。
任何帮助将不胜感激。
有人告诉我用冒号替换等号并添加反斜杠,但是,它似乎不起作用:
$ curl \
> -F 'message:{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\": true}}}' \
> -F 'filedata=@/tmp/shirt.png;type=image/png' \
> "https://graph.facebook.com/v6.0/me/message_attachments?access_token=<MY-TOKEN>"
Warning: Illegally formatted input field!
curl: option -F: is badly used here