I am developing an Asp.NET MVC application. In my application, I need to push notifications to Android Devices using Firebase. This is the consequence of this question - https://stackguides.com/questions/40416654/unable-to-push-firebase-notifications-to-multiple-devices-using-webclient-in-asp I asked.
After I searched for solutions, I realized that I should use Topic Messaging of Firebase - https://firebase.google.com/docs/cloud-messaging/android/topic-messaging. But when I use topic messaging and push from server, it always return Error=InvalidRegistration error.
I subscribe to a topic in Android like this
FirebaseMessaging.getInstance().subscribeToTopic("newsTopic");
Then I push like this in 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";
}
}
}
But when I push, it returns this Error=InvalidRegistration.
Update
I tried replacing
values["to"] = "/topics/newsTopic";
with this
values["condition"] = "'newsTopic' in topics";
It returns, Error=MissingRegistration