Firebase Cloud Messaging API (v1) Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I recently got this dreaded email from Google saying we're writing to let you know that starting June 20th 2024 the Legacy Firebase Cloud messaging apis will be discontinued what that means is if you're using Firebase for your Cloud messaging you will no longer be able to use the Cloud messaging API Legacy beginning June 20th 2024 you will have no choice but to switch to Firebase Cloud messaging API V1 this would have been great if not for the Google Firebase documentation you could literally be spending days reading this documentation and still have no idea how it works but thankfully something called nextchat.ai now exists this is the easiest way I know of to learn how to use the Firebase Cloud messaging API V1 we'll go through how to start a conversation on nextchat.ai to learn how to use the Firebase Cloud messaging API you'll want to create a free account if you haven't already go ahead and log in I'll go through this conversation I had with it I also if you click this Global prompt Library you can search for it I created a Firebase Cloud messaging API you can copy this this is the conversation and paste it into your conversation and start asking questions and so we'll go through these steps together the first thing I asked is do you know how the Firebase Cloud messaging API V1 works and thankfully it does it tells you the different steps you have to go through you first need to set up a Firebase project which if you've already created a project if you go to console.firebase.google.com these are your projects I'll just click on this one Android app The Next Step says you need to register your client devices this has to do with the app itself in your app code you'll need to register your devices with fcm this is usually done using a service like nativenotify.com to send push notifications with the Expo framework the react native framework or the flutter framework whenever you install whatever push notification service this you're using and you copy their code into your code so for example with Native notify all you have to do is import this register in in push token copy this function into your app and you're already finished this register in and push token will automatically do this next step for you it will register the phone or the device that's using this app to fcm for you so this step again is just all about the push notification service you decide to use it then goes through talking about how to send messages receive messages get reports and so then I ask for more detail I mentioned how I'm currently using the Cloud messaging API Legacy which if you come back to your Firebase app click this gear icon in the top left corner click project settings that's where you can go to your Cloud messaging and down here is the Cloud messaging API Legacy and as you can see it's also saying you have to migrate to this by February 23rd 2024 so this is normally what I used to send push notifications a server key like this but now I need to know how to use the Firebase Cloud messaging API instead and so I explained that to next chat I said I'm currently using the old way but Google is telling me I need to upgrade to the new way and I just asked how would I send push notifications using the new way can you still use an API to send the requests can you show me an example then it showed me how to do it so if you still want to use an HTTP post request to send a push notification this is what your endpoint will look like and the only part here you need to update is your project ID if you come back to your Firebase app go to General right here again we're still if you click this gear icon in the project settings if you go to General that's where you can find your project ID right here it should look something like this if you hover over the question mark it says a user assigned unique identifier for your Firebase project this identifier may appear in URLs or names for some Firebase resource courses so that there is what you would copy and paste into this post request where it says project ID and then here is an example of the request you could say post here's the post endpoint the host fcm dot Google apis.com this is some of the information that can go in your header for authorization this is the important part and this is not in the documentation you'll need to have an authorization in your header with a bearer with your access token right here and I'm about to explain how to get your access token and then you would send the rest like normal you'd send a message to your user device token this is the token generated on your phone on your device that is registered with fcm and here's the notification and here's if you want to send data with it how you send data so my next question was how do I get the your access token because again if you go to the Firebase Cloud messaging API learn more it doesn't tell you because Google likes to keep you on your toes it doesn't want to make things simple if they wanted to make it simple they would have your access token somewhere like I don't know the general section or the project ID is but no that again would just be too easy in reality your access token is not even found on the Firebase website you have to go to a different website again I love how Google wants to keep you on your toes thankfully though nextchat.ai makes things super simple when I asked how do I get your access token it says you first have to enable fcm API for your project and it says go to this link here so I'm going to open this link in a new tab when you come here you want to make sure you're logged into the correct account you should then see your apps here all your projects from Firebase which again can be found here should now be found here in this cloud.google.com console and if it's not you can click create project but they should be there if you're logged into the correct account so it says look for Firebase Cloud messaging API I make sure it's enabled so for example I was in the Android app I'm going to click that you can control F and look for Firebase Cloud messaging API click on that and then look here at this status you want to make sure this says enabled if this is not enabled you'll need to enable it and I believe you'll be able to do that up here there's a button up here that says disable API so I'm assuming if it's not enabled currently you could probably click a button up here that says enable API I just have to take some time to say how much my blood is boiling right now I cannot believe a two trillion dollar company doesn't know how to write good documentation I can't believe I have to go all over the web just to get the simplest thing to work anyway the next step is create a service account so this part is important it says navigate to the service accounts page I'm going to right click that open that up again you'll want to make sure you're in the right account okay and so this took me to this service accounts page right here I'm going to again click on Android app it says click create service account and provide a name an optional description and choose a role such as Firebase admin SDK administrator click create there's a chance that was already done on firebase.google.com when you set up your app so for me I already had all of that filled out down here so I did not need to click create service account it was already there so if it's already there you do not have to click create service account but if it is not there you should click create service account follow the instructions and then once it's down here you can click on it make sure the account service is currently active you can name it whatever you want give it a description so once you've reached this page here where you'll see details permissions Keys metrics logs you can go on to the next step which is generate the access token the way you generate the access token is if you come back here click this Keys button right here Keys come down down here click add key click create new key say Json click create then it will download a Json file for you now this next step you could use Python to generate the access token for you but a much easier way is to just click close this and your key will show up here so finally we have reached the point of finding our key our access token key it's right here it shows up right there so this number right here would be your access key and so then if you come back to the example found at nextchat.ai you would put this access token here in your Bearer your access token replace your access token with that and you're officially set you can now send push notifications using the new Firebase Cloud messaging API let me know in the comments below how the Firebase documentation makes you feel does it make you feel all warm and fuzzy inside or does it make you want to bash your head through a window let me know if you have any questions in the comments below too I'll try my best to answer any questions you have like the video if you'd like to see more content like this don't forget to subscribe and hit the Bell icon to be notified when more videos come out thanks for watching and I'll see you next time
Info
Channel: Native Notify
Views: 52,413
Rating: undefined out of 5
Keywords: firebase, cloud, messaging, api, v1
Id: oNoRw69ro2k
Channel Id: undefined
Length: 9min 13sec (553 seconds)
Published: Mon Jul 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.