Guest User

Guest User

  • Tech Writer
  • 611
  • 126.4k

Firebase push notification c#

Jun 22 2020 1:53 AM
  1. var applicationID = "dno8ujDPEuWJXrRzudDK";  
  2. var senderId = "636408391381";  
  3. string deviceId = "*************";  
  4. WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");  
  5. tRequest.Method = "post";  
  6. tRequest.ContentType = "application/json";  
  7. var data = new  
  8. {  
  9. to = deviceId,  
  10. notification = new  
  11. {  
  12. body = obj_Parameter.Message,  
  13. title = obj_Parameter.TagMsg,  
  14. icon = "myicon"  
  15. },  
  16. priority = "high"  
  17. };  
  18. var serializer = new JavaScriptSerializer();  
  19. var json = serializer.Serialize(data);  
  20. Byte[] byteArray = Encoding.UTF8.GetBytes(json);  
  21. tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));  
  22. tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));  
  23. tRequest.ContentLength = byteArray.Length;  
  24. using (Stream dataStream = tRequest.GetRequestStream())  
  25. {  
  26. dataStream.Write(byteArray, 0, byteArray.Length);  
  27. using (WebResponse tResponse = tRequest.GetResponse())  
  28. {  
  29. using (Stream dataStreamResponse = tResponse.GetResponseStream())  
  30. {  
  31. using (StreamReader tReader = new StreamReader(dataStreamResponse))  
  32. {  
  33. String sResponseFromServer = tReader.ReadToEnd();  
  34. obj.Response = 1;  
  35. obj.ErrorMessage = sResponseFromServer;  
  36. }  
  37. }  
  38. }  
  39. }  
  40. }  
  41. catch (Exception ex)  
  42. {  
  43. obj.Response = 0;  
  44. obj.ErrorMessage = "Internal Server Error";  
  45. }  
  46. return obj;  
I have test this code but i have face this error -
 
{\"multicast_id\":9049684377314331171,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"InvalidRegistration\"}]}"
it's me parameter
{
"Message": "New Content!",
"TagMsg": "A new video has been uploaded."
}
 
Please solve this