firebase (fcm) says 401 unauthorized

守給你的承諾、 提交于 2019-12-04 06:14:55

Try replacing:

con.setRequestProperty("Authorization: key", "<YOUR API KEY>");

with:

con.setRequestProperty("Authorization", "key=<YOUR API KEY>");

Just Solved the problem for me, I changed the Server API Key, which is given on the Cloud messaging tab, in FCM Console. In Project Overview, Manage, there is the Cloud Messaging tab, it shows a SERVER API KEY use that may be. In json file client_api key and SERVER_API_KEY different!!

Based on Harco's answer, in the Firebase console look at "Project settings" (click on gear icon) and choose the "Cloud Messaging" tab. "Server key" is what you need.

Actual on 2017.06.28.

https://firebase.google.com/docs/cloud-messaging/server

"Make sure this is the server key, whose value is available in the Cloud Messaging tab of the Firebase console Settings pane. Android, iOS, and browser keys are rejected by FCM."

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!