Farhan Ali Farhan Ali - 1 year ago 194
Android Question

GCM 401 Not-Authorized

I am working with Android GCM. My application is live and it contains hundreds of users. I am using back-end of .NET (SOAP services with MS-SQL).

I've now accidentally deleted my GCM Server Key from Google Developers Console. Now, I am trying to send a notification, but it's showing a not authorized error response.

Help me. How to send notifications now? I don't wanna lose my users. That's why new Server Key is not an option for me. If you've good solution, please let me know. Thanks.

Answer Source

So just to stress on it, there is not way to recover a deleted Server Key. Before even deleting a Server Key in the Google Developers Console, a dialog appears saying:

This credential will be deleted immediately and permanently. Once deleted, it can no longer be used to make API requests.

I don't wanna lose my users.

You only deleted the Server Key which is used for Authorization. The 401 error is only an auth error that says that your sender has a problem authenticating. Not the end of a project.

You don't lose the users so long as you still have the registration tokens and it's corresponding Sender ID(s) exists.

The way that you have to do this now is for you to import your Google Developer Console project to Firebase Console, since as mentioned in the docs:

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.

Steps on how to import your project is like so:

  1. Go to your Firebase Console and click on IMPORT PROJECT.
  2. Select the project you want to import and your country.
  3. Click on ADD FIREBASE. After this, the new Project should be active.
  4. Then on left-side panel, click on the gear button and select Project Settings.
  5. Then go to the Cloud-Messaging Tab.

401 Authorization error is so common this past few months. Don't panic. See my answer here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download