首页 > 解决方案 > 在 ASP.NET Core 中使用 firebase 发送通知

问题描述

我有一个 ASP.NET Core 应用程序,它将使用 Firebase 发送一些通知。

我正在使用此代码通过 C# 发送通知消息。

启动.cs

public IServiceProvider ConfigureServices(IServiceCollection services)
{
   //...
   FirebaseApp.Create(new AppOptions()
   {
       Credential = GoogleCredential.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "key.json")),
   });
   //...
}

这是我如何发送通知的代码

try
{
    string ServerKey = "MY_SERVER_KEY";

    var message = new Message()
    {
        Notification = new Notification
        {
            Title = "Message Title",
            Body = "Message Body"
        },
        Token = ServerKey,             
    };

    return await FirebaseMessaging.DefaultInstance.SendAsync(message);
}
catch(Exception ex)
{
    return null;
}

问题是在我运行我的函数发送通知后,我收到以下错误:

SenderId 不匹配

我检查了文档和其他一些我没有找到如何放置发件人 ID 的地方。

标签: c#asp.net-corefirebase-cloud-messaging

解决方案


推荐阅读