0
votes

I'm implementing sending push notifications from my google-app-engine server to client apps. I'm receiving response 401 when sending post message to Firebase cloud messaging server (https://fcm.googleapis.com/fcm/send). I've followed instructions in https://firebase.google.com/docs/cloud-messaging/server, so I'm sending "Authorization" header with my server key. When I'm checking for validity of the key with curl:

curl --header "Authorization: key=$api_key" \
       --header Content-Type:"application/json" \
       https://fcm.googleapis.com/fcm/send \
       -d "{\"registration_ids\":[\"ABC\"]}"

I'm getting response:

{"multicast_id":6193339963814546500,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

Which should mean that my server key is valid. I followed "Recommended Actions" for 401 described in: https://firebase.google.com/docs/cloud-messaging/http-server-ref Apart from the last one: "Request originated from a server not whitelisted in the Server key IPs." Can that be the cause? How to check that?

1
I don't think the whitelist applies here (I can't even find one in the console). The answer is almost certainly that you're using the wrong server key (probably an Android/iOS client key).Kato
Solved the issue. It was problem with retrieving server_key from json badlyzlenyk
Nice! Glad you resolved it.Kato

1 Answers

0
votes

I solved the issue. It was my mistake. I wasn't truncating json to string properly and my server key wasn't in fact a correct one. Sorry for bother.