我正在开发一个Asp.NET MVC应用程序。在我的应用程序中,我需要使用Firebase将通知推送到Android设备。这就是这个问题的结果 - https://stackoverflow.com/questions/40416654/unable-to-push-firebase-notifications-to-multiple-devices-using-webclient-in-asp我问道。
在我搜索解决方案后,我意识到我应该使用Firebase的主题消息 - https://firebase.google.com/docs/cloud-messaging/android/topic-messaging。但是当我使用主题消息传递并从服务器推送时,它总是返回Error = InvalidRegistration错误。
我订阅Android中的主题
FirebaseMessaging.getInstance().subscribeToTopic("newsTopic");
然后我在asp.net
中这样推public string PushNotifications()
{
using (var client = new WebClient())
{
client.Headers.Add(string.Format("Authorization:key={0}", Utils.FirebaseServerKey)); //get from firebase
var values = new NameValueCollection();
values["to"] = "/topics/newsTopic";
values["data.message"] = "This is the test FCM test message";
var response = client.UploadValues("https://fcm.googleapis.com/fcm/send", values);
string responseString = Encoding.Default.GetString(response);
if (!string.IsNullOrEmpty(responseString))
{
return responseString;
}
else
{
return "Something went wrong";
}
}
}
但是当我按下时,它会返回此错误= InvalidRegistration。
我试过替换
values["to"] = "/topics/newsTopic";
用这个
values["condition"] = "'newsTopic' in topics";
返回,Error = MissingRegistration
答案 0 :(得分:0)
当我没有包含“Content-Type = application / json”标题时,我可以重现该问题(Error = MissingRegistration)。您可以尝试添加Content-Type标题吗?