Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get gcm_sender_id for website in Firebase

I am trying to use push notification for my web site..

I am trying fcm. In the Google documentation (https://firebase.google.com/docs/cloud-messaging/js/client) they told us to use gcm_sender_id in manifest.json file, but I don't find it any where in firebase page https://console.firebase.google.com/project/fir-98798789/overview

Also they have mentioned

Don't confuse the "browser sender ID" with the project-specific sender ID value shown in your Firebase project settings. The browser sender ID for manifest.json is a fixed value, common among all FCM JavaScript clients.

like image 984
scriptkiddie1 Avatar asked Feb 14 '17 11:02

scriptkiddie1


People also ask

How do I find my firebase Sender ID?

Click the Cloud Messaging tab next to the General tab. The Project credentials section appears. The Project credentials section displays the Firebase Cloud Messaging token, Sender ID, and the Server key. Copy Sender ID.


2 Answers

The sender ID that you enter in the manifest.json of your web app is independent of your Firebase project. It is the same for all web apps (yours, mine, everybody's):

"gcm_sender_id": "103953800507"

So just copy/paste the line above into the manifest.json for your project. See this section of the FCM documentation.

like image 177
Frank van Puffelen Avatar answered Sep 19 '22 06:09

Frank van Puffelen


Seems like Firebase Messaging actually works even if you skip this step. Look at https://web-push-demo-11213.firebaseapp.com as an example.

This demo website doesn't even have a manifest but is able to talk to FCM, get tokens, refresh them and so on.. Sorry you won't be able to actually send a push though since you don't know the auth key, but you get the idea - I've tested it, it works.

In light of this, not sure why this manifest requirement though.

Also, looking at the FCM SDK source on github, looks like they only throw an error if you have a manifest with a gcm_sender_id that's not 103953800507. For everything else (the gcm_sender_id field in manifest missing, or even the manifest itself missing from the website), it works as fine.

See the code here: https://github.com/firebase/firebase-js-sdk/blob/master/packages/messaging/src/controllers/window-controller.ts#L329-L355

like image 34
abhishekcghosh Avatar answered Sep 21 '22 06:09

abhishekcghosh