当我的后端服务器向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\"}"
我明白了:
Unauthorized Unauthorized
Error 401
在故障排除中它说:
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.
我对此有疑问:
卷曲请求中的标题是否正确?
他们的意思是"api_key"(AIzaSy ......)或项目编号如8305134 ....
如何将服务器密钥IP列入白名单?
如果我正在运行curl命令,是否必须将计算机的IP地址列入白名单?
Vijay C.. 28
他们的意思是"api_key"(AIzaSy ......)或项目编号如8305134 ....
它表示应在curl脚本中添加的服务器密钥.项目编号不应用于在服务器端发送消息.
要创建新的服务器密钥,请按照步骤操作,
转到https://cloud.google.com/console/project
单击您的项目
转到左侧面板上的API和auth
在左侧面板的子菜单中选择凭据
在公共API访问下,单击" 创建新密钥 "
选择"服务器"
在下一个对话框中,指定列入白名单的IP(如果有).留空,请求将来自任何IP
点击创建.
您会发现新的服务器密钥是在" 公共API访问 " 下创建的
此密钥用于在服务器端的脚本中发送消息.
如何将服务器密钥IP列入白名单?
您可以在创建服务器密钥时将其列入白名单.
如果我正在运行curl命令,是否必须将计算机的IP地址列入白名单?
出于测试目的,您不必指定IP.出于商业目的,您可能想要.
如" 入门指南"中所述,警告设置IP为0.0.0.0/0将允许所有IPv4地址,但不允许IPv6.