Javacode here:
function sendTextMessage(sender, text) {
messageData = {
text:text
}
request({
url: 'https://graph.facebook.com/v2.6/me/messages',
qs: {access_token:token},
method: 'POST',
json: {
recipient: {id:sender},
message: messageData,
}
}, function(error, response, body) {
if (error) {
console.log('Error sending message: ', error);
} else if (response.body.error) {
console.log('Error: ', response.body.error);
}
});
}
And C# code, I want to replace "?access_token=dshfhsfhrthytrghfgbfhnytfht" by code, because the url use type POST. I find out that I can use WebRequest but i don't know how I use WebRequest to add Json data, so I use HttpWebrequest, Http Webrequest can add query string by StringBuilder , but how i Write post data and json? In this code I just Write json data
public void sendTextMessage(string sender, string text) {
string json = "{ recipient: {id:"+sender+ "} , message: {text: \""+text+"\"}";
var request = (HttpWebRequest)WebRequest.Create("https://graph.facebook.com/v2.6/me/messages?access_token=dshfhsfhrthytrghfgbfhnytfht");
request.ContentType = "application/json";
request.Method = "POST";
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}