【发布时间】:2016-11-04 08:26:28
【问题描述】:
我正在开发一个 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";
}
}
}
但是当我推送时,它会返回这个 Error=InvalidRegistration。
更新
我尝试替换
values["to"] = "/topics/newsTopic";
有了这个
values["condition"] = "'newsTopic' in topics";
返回,Error=MissingRegistration
【问题讨论】:
-
鉴于代码与your previous question 中的代码几乎相同,并且您会收到相同的错误消息,因此最好使用edit to that question。
标签: asp.net firebase push-notification firebase-cloud-messaging