47.REST API To Call Push Notification | Firebase Messaging Flutter | Chat App

  Рет қаралды 11,339

Harsh H. Rajpurohit

Harsh H. Rajpurohit

Күн бұрын

In this video, We will automatically send push notification to chat user when a new message is send to user using Restful APIs with Post Request.
Create chatting app similar to whatsapp with Flutter & Firebase.
Next Video: • 48.Create Custom Notif...
Previous Video: • 46.Send Push Notificat...
GitHub Codes: github.com/Har...
Complete Playlist: • Chat App In Flutter & ...
My Learning Journey: • How To Learn Android D...
Free Android (+ Kotlin) Courses 😃:
🎵 Music Player App: • Music Player App In An...
▶️ Video Player App: • Video Player App In An...
🌐 Private Browser App: • Web Browser App Course...
🔒 Firebase Authentication: • Android Authentication...
Free Flutter Courses 😃:
🅵 Flutter 3 (Beginners): • Flutter Tutorial (App ...
💬 Chat App (Firebase): • Chat App In Flutter & ...
Flutter development VS Code in Hindi.
(A Humble Request) 😊
Share Content with One Who is in Need.
Thanks for watching.

Пікірлер: 51
@harshRajpurohit
@harshRajpurohit 7 ай бұрын
For anyone facing the issue with the notifications. Credit Goes to Mafaz Khan for this Research. Observation 1: The notifications API needs to be migrated to v1 Fix: 1. Change URL to this fcm.googleapis.com/v1/projects/PROJECTID/messages:send 2. Obtain your project id from firebase-> project settings -> general (Here you can find your project ID. Observation 2: Your server key is no longer needed Fix: 1. Instead go to your Google cloud console(This is the page from where you generated the API key. 2. Search for service account, then click for your current project (It should liik like this "firebase-adminsdk-sz6nt@YOURPROJECTNAME-87ebc.iam.gserviceaccount.com" 3. Once you click on the account you will find tabs, now go to keys tab and create a new key(This should download a json file) 4. Now open the json file and copy the whole code as this will generate our bearer token Observation 3: We need extra packages and coding to generate bearer token Fix: 1. First add this package (googleapis_auth:) to your pubspec.yaml. 2 Now the coding part, create a new file in apis folder and name it access_firebase_token.dart. 3. Copy and paste the below code: Code: import 'package:googleapis_auth/auth_io.dart'; class AccessFirebaseToken { static String fMessagingScope = "www.googleapis.com/auth/firebase.messaging"; Future getAccessToken() async { final client = await clientViaServiceAccount( ServiceAccountCredentials.fromJson( { PASTE YOUR GENERATED JSON FILE CODE OVER HERE, BE MINDFUL TO NOT COPY THE CURLY BRACES JUST PASTE THE CODE IN HERE AND IMPORT THE ERRORS } ), [fMessagingScope], ); final accessToken = client.credentials.accessToken.data; return accessToken; } } Observation 4: The code needs to be changes for sendPushNotifcation function Fix: 1. Just copy the code below and import the errors Code: static Future sendPushNotification( ChatUser chatUser, String msg) async { AccessFirebaseToken accessToken = AccessFirebaseToken(); String bearerToken = await accessToken.getAccessToken(); final body = { "message": { "token": chatUser.pushToken, "notification": { "title": me.name, "body": msg }, } }; try { var res = await post( Uri.parse('fcm.googleapis.com/v1/projects/YOURPROJECTID/messages:send'), headers: { "Content-Type": "application/json", 'Authorization': 'Bearer $bearerToken' }, body: jsonEncode(body), ); print("Response statusCode: ${res.statusCode}"); print("Response body: ${res.body}"); } catch (e) { print(" sendPushNotification: $e"); } } Check for notification and it will work😊 Official Docs: firebase.google.com/docs/cloud-messaging/migrate-v1
@muhammadjaved4278
@muhammadjaved4278 Жыл бұрын
Thank you. Your explaining way is very good.😇🥰
@mohamedayman5240
@mohamedayman5240 Жыл бұрын
thankssssssssssssssss u are great,, even when i dont know indian i understand
@WanderWiseAdmin
@WanderWiseAdmin 4 ай бұрын
Thank you so much for the tutorial!!
@gautamsolanki3644
@gautamsolanki3644 6 ай бұрын
thnxx for your pin comment
@chihab3829
@chihab3829 Жыл бұрын
vary helpful
@Justin-nw7xi
@Justin-nw7xi Жыл бұрын
If same user sends multiple messages to another user it is sending multiple notification . How to group all the messages together and send as single notification ?
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Actually that is a bit difficult for now because flutter is not that well developed for handling notifications, so maybe in future I will give it a try. And you can research a bit and if you find any solution then let me know.
@bilalarslan74
@bilalarslan74 5 ай бұрын
Can you please make an updated version of this video? There seems to be high demand. I tried the method you wrote in the description but I couldn't do it. Thank you from now.
@harshRajpurohit
@harshRajpurohit 5 ай бұрын
I've already updated my github project for this feature so you can refer to it (I've also added necessary comments too). Project link: github.com/HarshAndroid/ApnaChat-Realtime-Chat-App-In-Flutter-Firebase
@bilalarslan74
@bilalarslan74 5 ай бұрын
@@harshRajpurohit OK thanks. I will try to solve it
@gautamsolanki3644
@gautamsolanki3644 6 ай бұрын
its work on my real device but not work emulator anroid 11 14
@abhaykevat3997
@abhaykevat3997 8 ай бұрын
why we use postman i dont understand and what you did in last video
@harshRajpurohit
@harshRajpurohit 8 ай бұрын
Actually Postman is an API client means it can call APIs directly without any coding (so it's good for testing any API or service quickly without actually writing code for it). And I just used postman to test the api, if it's working or not? And if it works then code and use it in the app.
@ShaanCh-k7s
@ShaanCh-k7s Ай бұрын
Which os you use in this video?
@harshRajpurohit
@harshRajpurohit Ай бұрын
Deepin OS Linux
@BUNNY-wq4ms
@BUNNY-wq4ms 2 ай бұрын
Hello namaskar. why servery key deprecated
@harshRajpurohit
@harshRajpurohit 2 ай бұрын
Actually that only google knows. But for an updated guide you can refer to the first pinned comment or refer to the official docs or check out my github codes for more help.
@Arbic_calligraphy65
@Arbic_calligraphy65 Жыл бұрын
nice
@syedirfanhussaini7296
@syedirfanhussaini7296 Жыл бұрын
bhai, which linux distro you are using?
@harshRajpurohit
@harshRajpurohit Жыл бұрын
I'm using Linux Deepin Distro.
@mahimakumari7961
@mahimakumari7961 9 ай бұрын
In response body I am getting error invalid registration
@harshRajpurohit
@harshRajpurohit 9 ай бұрын
Refer to the first pinned comment because the API is changed a bit so you need to update codes accordingly.
@newbee936
@newbee936 Жыл бұрын
I have installed app on two phones one with android 10 is working perfectly and the other with android 12 version is not showing notifications but in code it gets success message but It shows notification after a really long time what should I do?
@harshRajpurohit
@harshRajpurohit Жыл бұрын
That's a bit weird because I'm also using an Android 12 device and it's working fine on my side. I think you need to google a bit or try on some other devices too.
@templetonmeshack2816
@templetonmeshack2816 8 ай бұрын
Hello, may you please do this video using the FIREBASE CLOUD MESSAGING API V1 instead of Cloud messaging API LEGACY🙏🏾
@harshRajpurohit
@harshRajpurohit 8 ай бұрын
Currently it's a bit difficult for me but you can try yourself, you will learn new things from it (and you can also refer to the pinned comment for more help).
@templetonmeshack2816
@templetonmeshack2816 8 ай бұрын
I have been trying, I'm stuck on where I have to replacing the serverKey with the accessToken, This part on google docuentation is not clear for me, Ive been trying for days now.@@harshRajpurohit
@chihab3829
@chihab3829 Жыл бұрын
how can i add a function when the user click the notification the app opened a specific screen not the main ???
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Actually it will require a little effort and testing. Try referring to the article below about how to do it. I hope it will be helpful to you. stackoverflow.com/questions/48403786/how-to-open-particular-screen-on-clicking-on-push-notification-for-flutter#:~:text=You have to use third,onMessage (app in foreground).&text=To provide the payload use,defined the intent for it.
@ankitpurohit18
@ankitpurohit18 Жыл бұрын
👍👍👍👍👍
@SumitKushwaha-ct6dc
@SumitKushwaha-ct6dc Жыл бұрын
i'm getting the same response as postman when I run the code, but with postman I get the notification, in code it gets success message but no notification
@harshRajpurohit
@harshRajpurohit Жыл бұрын
I think you might be using the fcm token of the same device through which you're sending push notification or device might be in foreground.
@abhaykevat3997
@abhaykevat3997 8 ай бұрын
push notification not showing what can i do now? also not on cmd
@harshRajpurohit
@harshRajpurohit 8 ай бұрын
Actually the api for push notifications is updated or changed recently, so you can refer to update ones on official docs (you need to change coding a little bit like api url and authentication key as bearer). Doc link: firebase.google.com/docs/cloud-messaging/migrate-v1
@abhaykevat3997
@abhaykevat3997 8 ай бұрын
@@harshRajpurohit pls provide updated code
@varunmaheshsingh2670
@varunmaheshsingh2670 Жыл бұрын
bro while receiving notifications it is showing me on the notification pop up not the name of the person who sent me the message
@harshRajpurohit
@harshRajpurohit Жыл бұрын
Actually I might have missed it, so sending our name with notification. Just use chatUser.name while sending title with notification.
@abhishekbansal8798
@abhishekbansal8798 9 ай бұрын
i am getting error 403 while making api call
@harshRajpurohit
@harshRajpurohit 9 ай бұрын
This error is because I think auth key is not valid or sent properly.
@abhishekbansal8798
@abhishekbansal8798 9 ай бұрын
@@harshRajpurohit I got the solution the api I was using today was deprecated I followed documentation and got the result
@harshRajpurohit
@harshRajpurohit 9 ай бұрын
Can you share the updated api or docs here, so it can help anyone else in future.
@abhishekbansal8798
@abhishekbansal8798 9 ай бұрын
@@harshRajpurohit thanks your video was helpful firebase.google.com/docs/cloud-messaging/migrate-v1
@abhaykevat3997
@abhaykevat3997 8 ай бұрын
@@abhishekbansal8798 how to solve this error pls help
@shaikmujahid-hi5uk
@shaikmujahid-hi5uk 4 ай бұрын
Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0 W/ProviderInstaller( 4352): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0. I am facing this error
@harshRajpurohit
@harshRajpurohit 4 ай бұрын
Actually this api is deprecated so it's not working, you can refer to the pinned comment of this video about how to migrate. And I have also updated my github codes as per new api, so you can also refer to it.
48.Create Custom Notification Channel In Flutter | Chat App
8:45
Harsh H. Rajpurohit
Рет қаралды 6 М.
Man Mocks Wife's Exercise Routine, Faces Embarrassment at Work #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 6 МЛН
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 61 МЛН
Flutter and Firebase - Send & Receive Notification
19:06
Coding Orbit
Рет қаралды 8 М.
I don't need Firebase anymore! I use Appwrite Cloud Functions
8:34
Adrian Twarog
Рет қаралды 38 М.
How To Send Flutter Push Notifications using NodeJS
31:41
Snippet Coder
Рет қаралды 19 М.
Beginners: WATCH THIS before learning FLUTTER BLOC
20:59
AJ Flutter Tutorials
Рет қаралды 16 М.
46.Send Push Notification | Firebase Messaging Flutter | Chat App
16:29
Harsh H. Rajpurohit
Рет қаралды 17 М.