如何解决 Android GCM 401 错误? [英] How to Troubleshoot Android GCM 401 error?

查看:22
本文介绍了如何解决 Android GCM 401 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试连接到 Google Cloud Message Server 时遇到许多 401 未经授权 错误.

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.

API 密钥工作正常,推送通知(最终)到达,但同时我收到了很多 401 错误.

The API key was working ok, the push notifications arrive (eventually), but meanwhile I get a lot of 401 errors.

我已经在控制台上验证了服务器 IP 地址白名单中:

I've verified on the console that server IP address is on the white list:

在遵循 Google 故障排除指南时,我得到了令人惊讶的结果:

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>

有时,相同的 curl 命令可以工作,有时它在控制台或命令行中也没有任何变化...我已经多次检查了密钥和允许的 IP).

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).

我已经检查了所有 stackoverflow 问题并测试了所有建议,但即使从白名单中删除所有 IP(以允许来自任何 IP 的请求),行为仍然相同,有时它会起作用有时它不会'

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.

推荐答案

经过多次检查并没有找到好的结果,我们给出的唯一解决方案是创建一个新项目(第三个是因为我们之前已经用新的 API 密钥做过这件事,这第三次成功了.

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.

这篇关于如何解决 Android GCM 401 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆