Firebase 401未经授权的错误FCM [英] Firebase 401 unauthorized error FCM
问题描述
我正尝试测试Firebase Cloud消息传递API,因为控制台无法提供所有功能(尤其是在后台运行应用程序时自定义通知).但是由于某些原因,我无法使其正常工作,并且始终显示401错误.我调查了这种情况的原因,并在重新生成新的服务器密钥后进行了尝试,但是错误仍然保持不变.令人惊讶的是,当我生成新的服务器密钥时,它没有反映在Firebase控制台中,并且显示服务器密钥为空.另外,我尝试将我的IP地址添加到服务器白名单IP中,但还是没有运气.我已经附上了我对Postman所做的请求的屏幕截图(我用服务器密钥代替了 serverKey .
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.
推荐答案
我从您的屏幕截图中注意到您正在使用"key:serverKey".您可以尝试改用"key = serverKey"吗?
I noticed from your screenshot that you were using "key: serverKey". Could you try using "key=serverKey" instead?
您也不需要"POST fcm.googleapus.com/fcm/send";这是不正确的json,会解释您所看到的错误.该请求的URL已在其他位置定义,因此请将其从有效负载中删除.
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.
这篇关于Firebase 401未经授权的错误FCM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!