如何在PHP后端中集成新的Google Cloud Messaging?
当我的后端服务器向GCM服务器发送post请求时,我收到HTTP 401的授权错误.
我按照这里描述的步骤:
http://developer.android.com/google/gcm/http.html#auth_error
>> api_key=AIzaSyDEy3...
>> curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_id\":\"ABC\"}"
Run Code Online (Sandbox Code Playgroud)
我明白了:
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)
在故障排除中它说:
Authentication Error
The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:
1. Authorization header missing or with invalid syntax.
2. Invalid project number sent as key.
3. Key valid but with GCM service disabled.
4. Request originated from a server not …Run Code Online (Sandbox Code Playgroud) android push-notification http-status-code-401 google-cloud-messaging
我实现了一个在我的计算机上运行的GCM推送通知服务(至少在开发期间).
为此,我基本上格式化并发送请求https://android.googleapis.com/gcm/send.
对于身份验证,我显然使用了我在Google Developers控制台上生成的服务器密钥.
我测试了它并且它完美地工作(设备接收推送通知,它实际上该死的快).
我在当天多次发送这些推送通知,但昨天我遇到的情况是请求发送返回a 401(代表需要的身份验证).我的要求与往常完全一样.我重复了4次同样的结果然后突然,它再次工作并返回了一个200.
我不知道为什么会发生这种情况.根据此文档,401只有在以下情况下才会发生:
- 授权标头丢失或语法无效.
- 作为密钥发送的项目编号无效.
- 密钥有效但GCM服务已禁用.
- 请求源自服务器密钥IP中未列入白名单的服务器.
这些条件在不同的呼叫之间没有变化.
是否有某种阈值或配额可以解释这一点?或者是否存在关于在发生这种情况时该怎么做的指南?