【问题标题】:Firebase Topic Messaging always return InvalidRegistration error when push notifications in ASP.NET在 ASP.NET 中推送通知时,Firebase 主题消息传递始终返回 InvalidRegistration 错误
【发布时间】: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

【问题讨论】:

标签: asp.net firebase push-notification firebase-cloud-messaging


【解决方案1】:

当我没有包含“Content-Type=application/json”标头时,我可以重现问题(Error=MissingRegistration)。您可以尝试添加 Content-Type 标头吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    • 2020-06-05
    相关资源
    最近更新 更多