使用curl向Facebook聊天发送图像附件不起作用

时间:2017-10-22 18:53:03

标签: image facebook curl upload attachment

我正在尝试使用curl将图像附件发送到Facebook聊天。 我收到了说明表(https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment

curl  \
-F 'recipient={"id":"YYYY"}' \
-F 'message={"attachment":{"type":"image", "payload":{}}' \
-F 'filedata=@/home/dominic/site/drophere/hitcat.jpg;type=image/jpeg' \
"https://graph.facebook.com/v2.6/me/messages?access_token=XXXX"

我执行此操作后,会显示以下错误消息:

{"error":{"message":"(#100) Message cannot be empty, must provide valid attachment or text","type":"OAuthException","code":100,"error_subcode":2018034,"fbtrace_id":"DwlBQTqXCw\/"}}

找不到我的错误。

2 个答案:

答案 0 :(得分:2)

此外,他们的文档在这里有一个错误的JSON示例https://developers.facebook.com/docs/messenger-platform/send-messages

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/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"

请注意这里的EQUALS标志:

  

{ “is_reusable”=真}

此处应为:而不是=

答案 1 :(得分:0)

在&#34;有效负载&#34;:{}}之后,您似乎错过了}。您的代码应为:

curl  \
-F 'recipient={"id":"YYYY"}' \
-F 'message={"attachment":{"type":"image", "payload":{}}}' \
-F 'filedata=@/home/dominic/site/drophere/hitcat.jpg;type=image/jpeg' \
"https://graph.facebook.com/v2.6/me/messages?access_token=XXXX"