【发布时间】:2022-11-24 19:57:47
【问题描述】:
我正在开发 .NET Web API,我想将推送通知发送到我的 Android 应用程序。我已经配置了 Firebase,并且能够使用旧版 REST API 客户端发送到主题“foo-bar”。我现在想发送图像,我认为旧版 REST API 不再支持这些图像。
我已经创建了一个控制台应用程序并引用了 Google.Apis.FirebaseCloudMessaging.v1,但是关于如何正确使用它的文档似乎很少。
I have created the following code, based on what I could glean at the Github repository (https://github.com/googleapis/google-api-dotnet-client/blob/main/Src/Generated/Google.Apis.FirebaseCloudMessaging.v1/Google.Apis.FirebaseCloudMessaging.v1.cs)
static async Task PostMethod2()
{
BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
ApiKey = "<MY_API_KEY>",
ApplicationName = "<MY_PROJECT_NAME>"
};
FirebaseCloudMessagingService service = new FirebaseCloudMessagingService(initializer);
ProjectsResource PR = new ProjectsResource(service);
SendMessageRequest SMR = new SendMessageRequest()
{
Message = new Message()
{
Topic = "foo-bar",
Notification = new Notification()
{
Title = "Sparky Says Hello!"
},
Android = new AndroidConfig()
{
Notification = new AndroidNotification()
{
Image = "<My Image URL>"
}
},
Apns = new ApnsConfig(),
Webpush = new WebpushConfig()
}
};
SMR.Message.Apns.Payload = new Dictionary<string, object>();
SMR.Message.Apns.Payload.Add("mutable-content", 1);
SMR.Message.Webpush.Headers = new Dictionary<string, string>();
SMR.Message.Webpush.Headers.Add("image", "<My Image URL>");
SendRequest SR = PR.Messages.Send(SMR, "projects/<My Project ID>");
Console.WriteLine("Got Here");
}
The debugger goes through each of the lines OK, but no notification appears. I have no visibility on the return result. Can someone please assist? Thank you.
【问题讨论】:
标签: c# firebase-cloud-messaging