Reputation: 103
Good day,
I am trying to use this URL from FCM to send messages:
https://fcm.googleapis.com/fcm/send
With a header of
Authorization value of **key:*Key from Firebase Console***
Content-Type: **application/json**
The body consist of this:
{
"to" : "MyKey generated",
"notification" : {
"body" : "Hey",
"title" : "Hey"
}
}
But the result i always received is this:
{
"multicast_id": 7942550122547405787,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "MismatchSenderId"
}
]
}
The server key I got is from here:
My URL reference is the docs in FCM server.
I am testing this in Postman. Did I miss something? Thanks
Upvotes: 3
Views: 33299
Reputation: 369
Downloading google-services.json and GoogleService-info.plist files from the General tab of the Firebase console solved the problem.
Don't download the file that comes while creating the app. There might be chances for mismatching sender ids. So, the best way is to download the files from the general tab and place them in their respective folders.
Upvotes: 1
Reputation: 171
This problem simply means server and client used 2 different firebase projects. It most likely happens when you accidentally push wrong keys and mix up your Development, Staging or Production environments.
Steps to fix:
You can confirm the client environment against the server by sending a test push notification using the generated push token in your firebase console. You will only receive the test notification if the push token is used in the correct Firebase project.
Upvotes: 1
Reputation: 666
Posting FCM through POSTMAN
Authorization: key=YOUR-SERVER-KEY
Content-Type: application/json
Now click on Body
than select Row
and add value as object like below
Make sure Row is in JSON(application/json)
{
"to": "cpa8cZPjq-w:APA91bF122f1Rnhu9v47bL
YMajaNTHAIU5SzItDwTy9o2MCIveG0PlK78VPvp3d
CqjwnUKZ4
ngi1trSyM3_aXttW62iknFfbPGtjRLhZr6wq-3qFdboz8gzdOGPz**********",
"notification": {
"body": "Hello",
"title": "This is test message."
}
}
POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Upvotes: 1
Reputation: 9
This error is due to invalid tokens I solved this, enter the token correctly
Upvotes: 1
Reputation: 6406
Sounds like Google Services on your Android app has been configured incorrectly.
Log into Firebase console, open your project (click the gear icon). Under General tab, scroll down to "Download the latest config file" and click on the button to download google-services.json (which should include the correct project and sender ID)
Send this to your mobile devs to include in the app and once the app's sent a valid push token, try sending again.
Upvotes: 3
Reputation: 5329
the header must be like this
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
to check the validity of a server key
api_key=YOUR_SERVER_KEY
curl --header "Authorization: key=$api_key" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
if everything is ok so you need to recheck the senderId
Upvotes: 1
Reputation: 73721
According to the docs
A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.
So it sounds like you are trying to send a push notification to an ID that is not associated with the sender ID. You should verify that you have the correct keys in the correct places
Upvotes: 6