尝试连接到Google Cloud Message Server时,我收到许多401
未经授权的错误.
我们的代码在我们的测试服务器上运行了一段时间,但在生产的代码上它有时会失败.
API密钥工作正常,推送通知到达(最终),但同时我收到很多401
错误.
我在控制台上验证了服务器IP地址在白名单上:
在关注Google Troublesooting指南时,我得到了惊人的结果:
me@myserver:~$ :curl --header "Authorization: key=AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFFU" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"Unauthorized Unauthorized
Error 401
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\"]}"Unauthorized Unauthorized
Error 401
有时,相同的curl
命令有效,有时它也没有任何改变,也没有在控制台或命令行中...有时它工作,我认为密钥没关系(我已经仔细检查了密钥和允许的IP几次).
我已经检查了所有stackoverflow问题并测试了所有建议,但即使从白名单中删除所有IP(以允许来自任何IP的请求)行为仍然是相同的,有时它有效地工作了一些时间它没有
我检查了一些参考文献:
使用PHP的GCM(Google Cloud Messaging)
GCM http 401授权错误
GCM服务出现不可靠的401错误
GCM发送消息失败,401(未授权)
任何有关可能发生的事情的建议都将非常感激.