This issue has been known for quite sometime. See my full answer here for more details. But on a short answer, below are the details you need.
There is a visible note in the GCM docs saying:
Starting from Sept. 2016 new server key can only be created in the Firebase Console using the Cloud Messaging tab of the Settings panel. Existing projects that need to create a new server key can be imported in the Firebase console without affecting their existing configuration.
It would also seem that Migrating from GCM to FCM fixes the issue for 401 Unauthorized Error.
If you are just starting to use GCM, instead of creating a project in the Google Developers Console, do it in the Firebase Console. After creating the project, simply use the auto-generated Server Key. Here are the steps where to find the Server Key:
- Go to your Firebase Console and click on CREATE NEW PROJECT.
- Fill in your desired Project Name and select your Country. After this, the new Project should be active.
- Then on left-side panel, click on the gear button and select Project Settings.
- Then go to the Cloud-Messaging Tab.
For old GCM projects, you can simply Import the project to the Firebase Console:
- Go to your Firebase Console and click on IMPORT PROJECT.
- Select the project you want to import and your country.
- Click on ADD FIREBASE. After this, the new Project should be active.
- Then on left-side panel, click on the gear button and select Project Settings.
- Then go to the Cloud-Messaging Tab.
For your GCM users, you don't have to worry so long as you have saved the registration tokens. So long as you use the corresponding Sender ID to send the push, FCM should still work with GCM.