Firebase 401 unauthorized error FCM

后端 未结 7 1392
自闭症患者
自闭症患者 2020-12-23 15:52

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).

相关标签:
7条回答
  • 2020-12-23 16:16

    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.

    0 讨论(0)
  • 2020-12-23 16:17

    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

    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

    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.

    0 讨论(0)
  • 2020-12-23 16:19

    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.

    0 讨论(0)
  • 2020-12-23 16:33

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

    you can use Server Key or Legacy server key

    0 讨论(0)
  • 2020-12-23 16:38

    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.

    0 讨论(0)
  • 2020-12-23 16:38

    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.

    0 讨论(0)
提交回复
热议问题