3

I have integrated GCM on client also made its Server side component. Every thing was working fine, I was able to send push notification from server to all the registered client. I am using google App engine as my server.

Problem came when:

  1. I changed the API Key on server.
    • Earlier I was using my personal GMail account to get API Key and all other access was through my account. Just before pushing the application live I moved the server to Production account and also changed the IDs as per production Ids. By Id I mean API Key, project ID, Production Keystore etc. Now the issue is when I want to send Push notification on Server I am getting URL Exception "HTTP Error 401: Unauthorized"

I tried doing: - Deleting my older Ids. - Deleting Old Public API access keys.

The same code works fine if I try to send Push notification from my old Server.

Does it has something to do with : Project package name and API key... which gets registered once can only be used....If yes How to delete that without changing the client project package name.

Please help we cannot go live with Old Server.

Ali Ashraf
  • 1,841
  • 2
  • 24
  • 27
  • This is the answer that helped me resolve this issue: [http://stackoverflow.com/questions/12619759/google-gcm-server-returns-unauthorized-error-401#15345696](http://stackoverflow.com/questions/12619759/google-gcm-server-returns-unauthorized-error-401#15345696) – zeusstl Feb 05 '15 at 07:34

4 Answers4

0

Check if ports 5228-5230(GCM ports) are open in the new server. It could be the problem.

Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
0

The issue can be beacause you are using the old server api key for the new server as well. For sending the push notification from server side, you need the api key generated with the help of server's public IP address.

Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
  • I used Android key, as API key for Server OLD, and now using New Android key for Server New. Still its not working. – Ali Ashraf Feb 03 '14 at 07:56
  • The google api console has changed a lot. you need to create server key instead of android api key by providing the server public ip address for sending push notification from server. – Eldhose M Babu Feb 03 '14 at 09:43
  • 1
    What if I am hosting my server on Google App Engine, on Cloud – Ali Ashraf Feb 03 '14 at 12:07
0

If it is testing purposes, make sure your server API key on the google console has the relevant ip addresses in the whitelist: 0.0.0.0/0 ::/0

These are for ipv4 and ipv6 ips

user2924714
  • 1,918
  • 1
  • 19
  • 26
0

Since this is an older question that was never answered but still gets views, I'll post here that this issue may have been obsoleted as the Cloud Console has gone through a couple of iterations since then.

Also, Google Cloud Messaging has been superseded by Firebase Cloud Messaging. New projects should use FCM, and existing projects are encouraged to upgrade in order to benefit from new features.

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

Adam
  • 5,697
  • 1
  • 20
  • 52