1

使用 curl 以下命令是正确的,并且 Facebook API 会回复预期的响应:

curl -F 'access_token=TOKEN' -F 'batch=[{"method":"GET", "relative_url":"facebook"},{"method":"GET", "relative_url":"youtube"}] ' https://graph.facebook.com

我想将其转换为 Ruby,但一直在努力寻找正确的语法。我尝试了以下变体,但没有运气:

uri = URI.parse('https://graph.facebook.com')

res = Net::HTTP.post_form(uri, 'access_token' => 'TOKEN', 'batch' => "[{'method':'GET', 'relative_url':'facebook'}]")

你能帮我吗?

4

1 回答 1

2

感谢这个问题这篇博文,这就是我的工作:

uri = URI("https://graph.facebook.com/")
req = Net::HTTP::Post.new(uri.path)
attach = {}

attach = {'batch' => [{"method" => "GET", "relative_url"=>"facebook"}].to_json}
req.set_form_data(attach.merge('access_token' => "TOKEN"))

res = Net::HTTP.new(uri.host, uri.port)
res.verify_mode = OpenSSL::SSL::VERIFY_NONE
res.use_ssl = true

response = nil
res.start do |http|
  response = http.request(req)
end
于 2013-01-05T14:59:15.547 回答