Reputation: 10867
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!
Upvotes: 18
Views: 20367
Reputation: 56
This worked for me try it:
1- Go to google cloud.
2- then go to API and Services.
3- then Enabled API and Services.
4- then turn on the cloud messaging and Turn on Firebase cloud messaging API.
Upvotes: 1
Reputation: 3100
Enable Firebase Cloud Messaging API in Google Cloud Platform.
Note that I wasn't able to find it in the section APIs & Services Dashboard but I had to browse the API Library
After you enable it you can find it in:
Google Cloud Platform > Navigation Menu > APIs & Services > Dashboard > Firebase Cloud Messaging API
Direct Link: https://console.cloud.google.com/apis/api/fcm.googleapis.com/overview
Credits to niocncn.
Upvotes: 0
Reputation: 171
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.
Upvotes: 10
Reputation: 10867
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.
Upvotes: 14
Reputation: 317412
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.
Upvotes: 14