Programing

Firebase 401 unauthorized error FCM

lottogame 2020. 11. 19. 07:47
반응형

Firebase 401 unauthorized error FCM


I'm trying to test out Firebase Cloud messaging APIs as all functionality is not available from console (notably customization of notifications when app is in background). But for some reasons, I cannot get it to work, and it always shows up 401 error. I investigated the reasons for this, and tried it after regenerating new server key, but the error remains constant. Surprisingly, when I generated a new server key, it is not reflected in Firebase console and it shows server key as empty. Also, I tried adding my IP address to the server whitelist IPs but still no luck. I've attached a screenshot of a request that I did with Postman (I substitue the server key in place of serverKey.

I'm stuck on this for a few hours and would really appreciate some help.enter image description here


I noticed from your screenshot that you were using "key: serverKey". Could you try using "key=serverKey" instead?

Also you don't need to have "POST fcm.googleapus.com/fcm/send"; this is not proper json and would explain the error you are seeing. The URL of the request is already defined elsewhere so remove it from the payload.


I don't know if someone uses the [Web API Key] as the [YOUR_SERVER_KEY] for POSTMAN test and keep getting '401 Error'. [Web API Key] is not [YOUR_SERVER_KEY].

You should go to your Firebase console and check this:

to get the correct Server key.

Hope it help.


I faced the same problem.

the problem was that I was using the legacy server key. when I used the new version of the server key the problem solved.

in your firebase console goto settings -> cloud messaging

then use the new server key. it is longer than the old version key.


go to https://console.firebase.google.com/u/0/project/[project-name]/settings/cloudmessaging/

Project credentials

you can use Server Key or Legacy server key


I too am facing the Same problem... I am using curl in php for posting and it works only if I have php files stored on my LocalHost server. When I try to use access the files via a free hosting online, then it say Unautorized 401.

So I would suggest if you can, use the Localhost.


I have the same problem at Server Side Code(C#).

You basically used wrong Server Key (or API Key) for service side code.

Follow below Link over stackoverflow posted by me (Helpful to find Server Key (or API Key) )

FCM (Firebase Cloud Messaging) Push Notification with Asp.Net


I was facing the same problem, i solved it by using the following steps

1- In the server from where you are sending push, Use the browser key only, you can get it from Firebase console or google api console as I have highlighted in the below images:-

Google api console

Firebase console, click on the project-->settings

Note : The Firebase console web api key and google console browser key are the same you can use either of them

enter image description here

enter image description here

2- If you follow the first step only you will get the Unauthorized error, to resolve this you need to authorize your browser key in google console by adding your server IP address from where you will send the push. Click on the edit pencil icon on the right side of your browser key in google api console, above first image

enter image description here

After adding your Ip address click save Make sure that your device token is not empty on which you are sending the push, I hope your push will be sent successfully now.

참고URL : https://stackoverflow.com/questions/37633188/firebase-401-unauthorized-error-fcm

반응형