我正在尝试使用FCM进行推送通知但是我收到错误
{" multicast_id":5438269995043250343,"成功":0,"失效":1," canonical_ids":0,&# 34;结果":[{"错误":" InvalidRegistration"}]}
我的代码是:
var applicationID = "AAAAU1NcEvw:APA91bF6V....blq3lFdU";
var senderId = "357...668";
string deviceId = "cmWVx1UBniA:APA91b.....ukG77K";
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/json";
var data = new
{
to = deviceId,
notification = new
{
body = "This is the message",
title = "This is the title",
icon = "myicon"
}
};
var json = jss.Serialize(data);
Byte[] byteArray = Encoding.UTF8.GetBytes(json);
tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));
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())
using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
// Response.Write(sResponseFromServer);
}
}
}
答案 0 :(得分:0)
由于错误状态,这意味着deviceId
未注册,您可能拼写错误或刷新了。
此外,如果您在发送到某个主题时遇到此问题,请确保您已添加前缀"/topics/"
,以便firebase的优秀人员知道您正在发送主题而不是特定的家伙。