如何解决Android GCM 401错误?

 semb 发布于 2023-01-19 17:50

尝试连接到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(未授权)

任何有关可能发生的事情的建议都将非常感激.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有