Firebase messaging/mismatched-credential
Solution 1
The issue was with my google-services.json
. My app uses two projects and was defaulting to the first project. Adding the second project json file ended up fixing this since it can now send the tokens to the proper project.
Solution 2
This error message can be found in the documentation for FCM.
It means that you've initialized the Admin SDK with a credential for a project that is not the same as the device registration token.
To put it another way: for security reasons, you can't simply send messages to any device token that you come up with. You can only send messages to device tokens via apps in the same project.
Solution 3
I faced the same problem. It took me two days to figure out that I need to enable the Firebase Cloud Messaging API through google cloud platform. Without enabling it, it also yields the error "mismatched-credential". I really wish that the error message could be more specific.
Joe Scotto
Writer of code, creator of videos, and taker of photos.
Updated on June 03, 2022Comments
-
Joe Scotto almost 2 years
I'm trying to send notifications to a specific device with Firebase but am getting the following error:
{"r": {"results":[{"error":{"code":"messaging/mismatched-credential","message":"The credential used to authenticate this SDK does not have permission to send messages to the device corresponding to the provided registration token. Make sure the credential and registration token both belong to the same Firebase project."}}],"canonicalRegistrationTokenCount":0,"failureCount":1,"successCount":0,"multicastId":5165415028752234000}}
I'm not sure what is causing this, I'm using the service account associated with the project and the proper device id.
Any help would be great, thanks!
-
Joe Scotto over 6 yearsBut the app I'm sending to is in the same project?
-
Doug Stevenson over 6 yearsI have no way of telling. You have to initialize with a credential that comes from the same project. That's something only you have access to.
-
Joe Scotto over 6 yearsI'm using the service account from the exact same project. Make no sense to me why it wouldn't be working.
-
Doug Stevenson over 6 yearsAll I can say is that you should double check all your data and make sure your service account is still valid. After you have double checked, if there is still a problem, contact Firebase support. firebase.google.com/support/contact/troubleshooting
-
BSQ about 6 yearsThank you ! Very annoy for enable !
-
Gillis Haasnoot about 6 yearsDid you find a solution? i have the same issue
-
ehacinom over 5 yearslike the answer says, I was trying to send push notifications to the wrong FCMToken (the 152 char token that my client app gets from Firebase after sending a deviceId to firebase)
-
Mark Adel over 5 years@Martin Z How do I achieve this?
-
Jay Sojitra about 5 yearsHi Joe, I am facing the same problem. But I didn't get your point. Can you please elaborate in detail?
-
Chris.D almost 5 years1) From the Firebase Console for your project go to settings service accounts. 2) Click the Service accounts for Google cloud platform link to go to the related google cloud project 3) From the left hamburger menu got to APIs and Services 4) Find "Firebase Cloud Messaging" (don't confuse it with "Cloud Messaging") 5) Enable API
-
Suraj Malviya over 4 yearsI faced the same problem, it is with Android studio, it is caching the JSON file across builds if not clean build the project at first place
-
Suraj Malviya over 4 yearsEnabling is not the requirement here. My project is working without enablilng the api from GCP as well.
-
MadMac about 3 yearsThe amount of times I have used the development google-services.json file by mistake!
-
Elemental almost 3 yearsIf you change your json credential files you need to do a clean on the project or android studio will not build the new credentials.