Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FCM HTTP v1 API sending message using .NET
// Learn more about F# at http://fsharp.org
open System
open Google.Apis.Auth.OAuth2
open FirebaseAdmin
open FirebaseAdmin.Auth
open FirebaseAdmin.Messaging
open System.Collections.Generic
open System.Collections.ObjectModel
let secretFilename = "path/to/secret_key.json"
[<EntryPoint>]
let main argv =
let firebaseApp =
FirebaseApp.Create(
AppOptions(
Credential = GoogleCredential.FromFile(secretFilename)))
let registrationToken = "device_token"
let message =
Message(
Data = (dict [
"title", "Pushy"
"body", "Pushy is alive and well"
] |> ReadOnlyDictionary),
Token = registrationToken)
try
let response = FirebaseMessaging.DefaultInstance.SendAsync(message) |> Async.AwaitTask |> Async.RunSynchronously
Console.WriteLine("Successfully sent message: " + response)
with e -> printfn "Failed to send message:\n%s\n%s" e.Message e.StackTrace
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.