Firebase Push Notifications with HTTP V1 API in Flutter | REST API Tutorial #firebase #flutter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome back to my Channel today I'll guide you through implementing Firebase push notifications in flutter using the HTTP V1 API and generating access tokens with a service account Json file but before we dive in make sure to like subscribe and hit the Bell icon for more amazing content let's get started for this tutorial I'll be using the project from my previous flutter authentication video to begin let's take a look at the Firebase Cloud messaging fcm documentation to use the HTTP V1 API will need two key components the fcm endpoint and a bearer token which is an ooth [Music] token since we're focusing on using rest API in this video we'll structure our request accordingly as mentioned earlier we'll require an ooth token to obtain this we'll use a service account and create a temporary access token for that we'll need a service account Json file let's dive [Music] in now navigate to your Firebase console in the project settings click on the Cloud messaging tab T and then proceed to click on manage service accounts before creating the Json file navigate to the I am section and ensure that your service account has all the required permissions once done go back to your service account click on the service account then go to the Keys Tab and click on create new key choose Json as the data type and it will automatically be downloaded now in your flutter project navigate to the pub speec yaml file and add the following packages HTTP Google apis and Google apis daro these packages are required to create the access token once done add the function to get the access token add the service account Json file to your function in the function the Scopes array contains the scopes for which the token is authorized create a client using the Google apis off and Google aps packages and obtain credentials using the service account Json done then return the access token from the credentials now let's create a function to send a rest API request for fcm push notifications first obtain the service key using the access token function in the message structure include a token which will be the fcm token of the device receiving messages additionally include a notification section for the data shown when the notification arrives and a data section to send custom data since we're sending the current devices fcm token included in the data section to create the HTTP request assemble all the necessary information and use jasonn code to encode the message then send the HTTP request to the Firebase Cloud messaging endpoint I have already created the send button simply add the send fcm message function to its unpressed option to trigger the notification now let's run the app when clicking on send I encounter error 43 it's because the project ID is missing in the fcm endpoint add it and then remove the string type from current fcm token rerun the app and you'll see it's working perfectly you can also modify the print statement to get different values in Firebase messaging on message. listen in the main dodart file that's all for today thanks for watching if you found this tutorial helpful don't forget to like share and subscribe stay tuned for more exciting flutter development content happy coding
Info
Channel: CodeMender
Views: 593
Rating: undefined out of 5
Keywords:
Id: 3qRRU9j01ZU
Channel Id: undefined
Length: 6min 5sec (365 seconds)
Published: Tue Apr 09 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.