Can';t使用Ruby在Messenger bot上上载文件
我无法在Ruby上上载图像 下面是在Bash中工作的代码:Can';t使用Ruby在Messenger bot上上载文件,ruby,facebook,curl,facebook-messenger,messenger,Ruby,Facebook,Curl,Facebook Messenger,Messenger,我无法在Ruby上上载图像 下面是在Bash中工作的代码: curl \ -F recipient='{"id":"USER_ID"}' \ -F message='{"attachment":{"type":"image", "payload":{}}}' \ -F filedata="@out.jpg" \ "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS" 以下是RestClien
curl \
-F recipient='{"id":"USER_ID"}' \
-F message='{"attachment":{"type":"image", "payload":{}}}' \
-F filedata="@out.jpg" \
"https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS"
以下是RestClient的翻译:
require 'rest-client'
require 'json'
file = "out.jpg"
tkn = "PAGE_ACCESS"
params = {
"recipient" => {"id" => "USER_ID"},
"message" => {
"attachment":{"type":"image", "payload":{}}
},
"filedata" => 'out.jpg'
}
puts params.to_json
begin
r = RestClient.post "https://graph.facebook.com/v2.6/me/messages?access_token=#{tkn}", params.to_json, :content_type => :json
rescue => e
puts e.response
end
以下是我得到的答案:
{"recipient":{"id":"USER_ID"},"message":{"attachment":{"type":"image","payload":{}}},"filedata":"@out.jpg"}
{"error":{"message":"(#100) Incorrect number of files uploaded. Must upload exactly one file.","type":"OAuthException","code":100,"fbtrace_id":"xxxxx"}}
我宁愿不使用gem-rubb来尊重它将要使用的体系结构。我也在为这个问题绞尽脑汁,欢迎有任何见解:/嗯,最后,我只是在Ruby内部执行了一个bash命令。虽然不是很好的结果,但它是有效的。虽然使用Node.js作为我的服务器端语言,但我还是找到了答案。我对Ruby一无所知,但问题的要点是FB messenger api希望将文件作为流进行多部分上传(这就是curl中的-F参数所做的)。