示例#1
0
        public static async Task MainFirebaseAdminAuth()
        {
            using (var firebase = new FireBase.Notification.Firebase())
            {
                await firebase.PushNotifyAsync(sender_Id, "Hello", "World");

                FileStream serviceAccount = new FileStream(path_to_private_key, FileMode.Open); // get the content of the file
                var        credential     = GoogleCredential.FromStream(serviceAccount);        // obtain the credential from the file
                serviceAccount.Close();                                                         //close the file (release the file handle, and possibly the thread!)
                var storage = StorageClient.Create(credential);                                 //storage details

                // Make an authenticated API request.
                //new FCMPushNotification().SendNotification("_title", "_message", "_topic", "deviceId");

                //firebase.PushNotifyAsync(id, "Hello", "World").Wait();
                var buckets = storage.ListBuckets(projectId);//Todo: check why the bucket was empty!
                //buckets
                foreach (var bucket in buckets)
                {
                    Console.WriteLine($"{bucket.Name}::{bucket}");
                }
                //FirebaseInstanceId.getInstance().getToken();
                //try
                //{
                //    FirebaseApp.Create(new AppOptions()
                //    {
                //        Credential = GoogleCredential.GetApplicationDefault(),
                //    });
                //}
                //catch (Exception ex)
                //{

                //}
                try
                {
                    var firebaseApp = FirebaseApp.Create(new AppOptions()
                    {
                        Credential = GoogleCredential.FromFile(path_to_private_key),
                    }, "My_Beautiful_App");
                    FirebaseMessaging.GetMessaging(firebaseApp);
                    new FCMPushNotification().SendNotification("title", "message", "topic", deviceId);
                    await new ProgramFirebaseAdminAuth().SendNotification(new List <string>()
                    {
                        deviceId, deviceId
                    }, "title", "body: some sort of msg to be sent to a device!");
                }
                catch (FirebaseException fex)
                {
                }
                catch (Exception ex)
                {
                }

                //try
                //{
                //    FirebaseApp.Create();
                //    // Initialize the default app
                //    var defaultApp = FirebaseApp.Create("defaultOptions");

                //    // Initialize another app with a different config
                //    var otherApp = FirebaseApp.Create("other");

                //    Console.WriteLine(defaultApp.Name); // "defaultOptions"
                //    Console.WriteLine(otherApp.Name); // "other"

                //    // Use the shorthand notation to retrieve the default app's services
                //    var defaultAuth = FirebaseAuth.DefaultInstance;

                //    // Use the otherApp variable to retrieve the other app's services
                //    var otherAuth = FirebaseAuth.GetAuth(otherApp);

                //}
                //catch (Exception ex)
                //{

                //}
            }
        }