Created
March 10, 2019 01:54
-
-
Save willsam100/8f249673187ffbfeffc26425bea19583 to your computer and use it in GitHub Desktop.
FCM HTTP v1 API sending message using .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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