GCM HTTP Error 401: Unauthorized

I have built-in GCM on the client also made its server-side component. Everything worked fine, I was able to send a push notification from the server to all registered clients. I use Google App Engine as my server.

The problem arose when:

  • I changed the API key on the server.
    • I used to use my personal GMail account to get the API key, and all the rest were available through my account. Just before I clicked on the application live, I moved the server to the production account, and also changed the identifiers according to the production identifiers. By identifier, I mean the API key, project identifier, production Keystore, etc. Now the problem is when I want to send a Push notification on the server. I get a URL exception "HTTP Error 401: Unauthorized"

I tried to do: - Removing old identifiers. - Removing old open access APIs.

The same code works fine if I try to send a push notification from my old server.

Is this related to: The name of the project package and the API key ... which is registered once, can be used only ... If yes How to remove this without changing the name of the client project package.

Please help, we will not be able to live with the old server.

+3
source share
4 answers

Since this is an older question that has never been answered, but it still gets submissions, I will post here that this problem may have been outdated since the Cloud Console has gone through a couple of iterations since then.

In addition, Google Cloud Messaging has been replaced by Firebase Cloud Messaging. New projects should use FCM, and it is recommended that existing projects be updated to use new features.

Firebase Cloud Messaging
https://firebase.google.com/docs/cloud-messaging/

+1

, 5228-5230 ( GCM) . .

0

The problem may be caused by the fact that you are using the old server api key for the new server. To send a push notification from the server, you need the api key generated using the server’s public IP address.

0
source

If this is testing, make sure your server API on the Google console has the appropriate IP addresses in the white list: 0.0.0.0/0 :: / 0

This is for ipv4 and ipv6 ips

0
source

All Articles