I'm getting many 401
Unauthorized errors when trying to connect to Google Cloud Message Server.
Our code was working for some time on our test server but on the production one it fails some times.
The API key was working ok, the push notifications arrive (eventually), but meanwhile I get a lot of 401
errors.
I've verified on the console that server IP address is on the white list:
When following Google Troublesooting guide, I get surprising results:
me@myserver:~$ :curl --header "Authorization: key=AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFFU" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
me@myserver:~$ curl --header "Authorization: key=AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFFU" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"
{"multicast_id":7560936933053964665,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
me@myserver:~$ curl --header "Authorization: key=AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFFU" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
Sometimes, the same curl
command works and sometimes it doesn't without any change nor in the console nor in the command line... As sometimes it works, I asume the key it's ok (I've double checked the key and the allowed IPs several times).
I have checked all the stackoverflow questions and tested all the suggestions, but even removing all the IPs from the white list (to allow requests from any IP) the behavior is still the same, some times it works some times it doesn't
Some references I've checked:
Any advice on what can be going on would be very appreciated.
Open your app's settings and select Intercom for Android. Then find the "Enable GCM" section.
Google Cloud Messaging (GCM) is a service that allows you to send push notifications from your server to your users' Android devices, and also to receive messages from devices on the same connection.
We evaluate GCM in real world experiments, and at a reasonable scale involving thousands of real users. Our findings reveal that the GCM message delivery is unpredictable, namely having a reliable connection to Google's GCM servers on the client device does not guarantee a timely message arrival.
GCM stands for Google Cloud Messaging. Every push notification receive on any Android device is sent by the GCM only. when sender sends an push notification then it goes to GCM. GCM receives that push and forward it to particular Android Device by its Unique device id.
After many checks and not finding a good result the only solution we could give was to create a new project (the 3rd one because we did it already before) with a new API key, and this 3rd time it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With