【发布时间】:2013-12-29 13:30:49
【问题描述】:
当我的后端服务器向 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\"}"
我明白了:
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
在故障排除中它说:
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 whitelisted in the Server Key IPs.
我对此有疑问:
- curl 请求中的标头是否正确?
- 它们是指“api_key”(AIzaSy…)还是像 8305134…这样的项目编号?
- 如何将我的服务器密钥 IP 列入白名单?
- 如果我正在运行 curl 命令,是否必须将我的计算机的 IP 地址列入白名单?
【问题讨论】:
-
对于刚刚浏览的其他人,如果您在没有进行任何特定更改(服务器密钥)仍然相同的情况下突然开始遇到此错误,您可能需要将您的项目导入 Firebase。看我的回答here。
标签: android push-notification google-cloud-messaging http-status-code-401