I have a mobile project uses firebase to get notifications.
My server side app is .Net
firebase documentation doesn't offer code for .Net
I just want to send notifications, and it would be great if the solution works on .Net 4
What I have tried:
The only code available for .Net is the initialization code
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile("jsonDBfile")),
});
I've found old code (I think for a previous version) but I didn't find the required parameters
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.Headers.Add(string.Format("Authorization: key={0}", "AIXXXXXX...."));
tRequest.Headers.Add(string.Format("Sender: id={0}", "XXXXX.."));
tRequest.ContentType = "application/json";
var payload = new
{
to = "e8EHtMwqsZY:APA91bFUktufXdsDLdXXXXXX..........XXXXXXXXXXXXXX",
priority = "high",
content_available = true,
notification = new
{
body = "Test",
title = "Test",
badge = 1
},
};
string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
}
}
}
}