This POST request using Ajax works perfectly:
var token = "my_token";
function sendTextMessage(sender, text) {
$.post('https://graph.facebook.com/v2.6/me/messages?',
{ recipient: {id: sender},
message: {text:text},
access_token: token
},
function(returnedData){
console.log(returnedData);
});
};
sendTextMessage("100688998246663", "Hello");
I need to have the same request but in Ruby. I tried with Net:HTTP, but it doesn't work and I don't get any error so I can't debug it:
token = "my_token"
url = "https://graph.facebook.com/v2.6/me/messages?"
sender = 100688998246663
text = "Hello"
request = {
recipient: {id: sender},
message: {text: text},
access_token: token
}.to_json
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
response = http.request(request)
response.body
How should I proceed to get the error or where did I go wrong ?