How to get fcm server key | Code2night.com
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

How to get fcm server key

Date- Nov 23,2023

2337

FCM Cloud Messaging


FCM(Firebase Cloud Messaging)

Firebase is used for sending notifications or cloud messaging. For sending notifications on Android devices we must have a firebase account.Now we will see how we can get the fcm server key. Follow the next steps


1. First of all search for FCM login on google as showed below 

2. Now click on Firebase cloud messaging link as showed below 

3. Now click on Go to console option as showed below 

4. Now on this screen click on add project if you don't have any existing project as showed below 

5. Now you have to add the project name and click on continue as showed below 


6. Now you have to click on continue as showed below 

6. Now you can select default account for firebase option as showed below and click on create project

7. Now your project will be created

8. Now on following screen click on settings icon and select project settings


9. Now select cloud messaging option here

10. Now click on three dots and click on manage api in google cloud console option as showed below

11. Now click on enable and this will enable fcm cloud messaging



12. Now reload the previous screen to see the server key

12. Now you can get the fcm server key as showed below



You can use following steps to use the server key in asp.net for sending notifications

Controller-

So, we will use

https://fcm.googleapis.com/fcm/send

this api for sending notifications, we will see how to pass required data and server key.So for this api you need to add some data which we will serialize and send with the request . So your Firebase model must be like this

public class FirebaseModel
    {
        [JsonProperty(PropertyName = "to")]
        public string To { get; set; }

        [JsonProperty(PropertyName = "data")]
        public NotificationModel Data { get; set; }
    }
	
public class NotificationModel
    {
       
        [JsonProperty("title")]
        public string Title { get; set; }
        [JsonProperty("body")]
        public string Body { get; set; }
    }

So you have to add these models in your .net project. After adding these models, we have to create one http request to the fcm api. You can check out this code

FirebaseModel firebaseModel = new FirebaseModel();
firebaseModel.Data = new NotificationModel();
firebaseModel.To = "Android Device Token";
firebaseModel.Data.Body = "Test Notificaton";
var serverKey = "Enter your firebase server key";
var authorizationServerKey = string.Format("key={0}", serverKey);
HttpRequestMessage httpRequest = null;
HttpClient httpClient = null;

var jsonBody = JsonConvert.SerializeObject(firebaseModel);

                   
httpRequest = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send");
httpRequest.Headers.TryAddWithoutValidation("Authorization", authorizationServerKey );
httpRequest.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json"); httpClient = new HttpClient(); var result = await httpClient.SendAsync(httpRequest);

So here we are addng some dummy data with device token in the firebase model. Then we are serializing the data and sending to the fcm api.

After this, you can check you will receive one fcm notification on the device for which device token was specified.

So this is how you can find and get the fcm server key and use that for mobile notifications.

Comments

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1210
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2025 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts