Paw*_*wel 36 android push-notification http-status-code-401 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 whitelisted in the Server Key IPs.
Run Code Online (Sandbox Code Playgroud)
我对此有疑问:
Vij*_*y C 28
他们的意思是"api_key"(AIzaSy ......)或项目编号如8305134 ....
它表示应在curl脚本中添加的服务器密钥.项目编号不应用于在服务器端发送消息.
要创建新的服务器密钥,请按照步骤操作,
此密钥用于在服务器端的脚本中发送消息.
如何将服务器密钥IP列入白名单?
您可以在创建服务器密钥时将其列入白名单.
如果我正在运行curl命令,是否必须将计算机的IP地址列入白名单?
出于测试目的,您不必指定IP.出于商业目的,您可能想要.
如" 入门指南"中所述,警告设置IP为0.0.0.0/0将允许所有IPv4地址,但不允许IPv6.
Max*_*nzo 19
更新:
谷歌已经改变了控制台,现在你必须:
弃用
我遇到了同样的问题......然后我意识到我还必须为Android添加Google Cloud Messaging.
希望它能帮到你!
Tys*_*son 16
我使用服务器密钥而不是API密钥解决了这个错误.您可以通过单击齿轮并单击"项目设置"从Firebase控制台获取服务器密钥,然后转到显示Cloud Messaging的选项卡并获取服务器密钥,普通服务器密钥和旧服务器密钥都将起作用.
这适用于Firebase和GCM,因此我们不需要单独声明两个键.
小智 11
终于找到了我的问题
我这样做了HTTP Authorization Header
Authorization:[Api key]
解
我在Authorization标头中缺少'key ='+ [你的Api密钥],
所以完整的HTTP标头将是
Authorization:key=Apikey
我有同样的问题.我正在使用http://developer.android.com/google/gcm/gs.html上的说明中提到 的Android Key 但我实际上必须使用服务器密钥从我的Fiddler窗口和PushSharp示例进行身份验证.
我不知道该curl
命令的语法,但奇怪的是,您指定的一个标头为 ,--header "key: value"
而另一个标头指定为--header key:"value"
。也许其中之一是不正确的。此外,您应该更改registration_id:ABC
为"{\"registration_ids\":[\"ABC\"]}"
.
它们指的是 API 密钥。
如果您在创建 API 密钥时未定义白名单 IP 列表,则默认情况下应将其列入白名单。
归档时间: |
|
查看次数: |
76358 次 |
最近记录: |