首页 > 解决方案 > Firebase:服务器响应不包含 JSON 对象

问题描述

我正在尝试运行 ASP.NET Core API 来发送 FCM 推送通知。

该 API 可与 Firebase SDK 配合使用。该代码基本上是文档中的代码:

初始化默认应用,configPath为JSON项目配置

FirebaseApp.Create(new AppOptions()
                    {
                        Credential = GoogleCredential.FromFile(configPath), //JSON con API Key credentials
                        
                    });

我发送的有效负载示例

//Send a message to the device corresponding to the provided
                //registration token.
                //var message = new Message()
                //{
                //    Data = new Dictionary<string, string>()
                //    {
                //        { "score", "850" },
                //        { "time", "2:45" },
                //    },
                //    Token = registrationToken,
                //    Notification = new Notification
                //    {
                //        Body = "Test"
                //    }
                //};

我发送的异步任务

string response = await FirebaseMessaging.DefaultInstance.SendAsync(payload).ConfigureAwait(false);

在本地一切正常(正在发送推送通知),配置似乎没问题,但在我的服务器上运行的已部署 API 返回以下错误:

在此处输入图像描述

服务器在 Windows 10 上运行,具有 Internet 连接,并且已经有其他 API(与 FCM 无关)工作正常。

作为一个 ServiceUnavailable 错误,我已经检查了它是否是 Firebase 问题,但如果是 Firebase 问题,它在本地将无法工作,对吗?

标签: c#firebaseasp.net-corefirebase-cloud-messaginggoogle-oauth

解决方案


推荐阅读