我正在尝试运行GCM演示。我已经在手机上构建并安装了应用程序,现在我正在尝试启动POST以激活推送。
我生成了google-services.json文件,并在此过程中获得了服务器密钥(API_KEY)和发件人ID(SID)。 (发件人ID是'到'设备/应用令牌?)
我正在尝试发送这篇文章:
curl -vvv -X POST --header "Content-Type: application/json" --header "project_id: default-demo-app-92a8c" --header "Authorization: key=<<API_KEY>>" --data @- "https://android.googleapis.com/gcm/send" << EOF
{
"to": "<<SID>>",
"data": {
"message":"Hello"
}
}
EOF
这是回复:
* Trying 74.125.29.95...
* Connected to android.googleapis.com (74.125.29.95) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.googleapis.com
* Server certificate: Google Internet Authority G2
* Server certificate: GeoTrust Global CA
> POST /gcm/send HTTP/1.1
> Host: android.googleapis.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: application/json
> project_id: default-demo-app-92a8c
> Authorization: key=AIzaSyA2GFGsoIeppqKRTpSc6m4sffGD8dzqryY
> Content-Length: 58
>
* upload completely sent off: 58 out of 58 bytes
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain; charset=UTF-8
< Date: Tue, 26 Jan 2016 21:46:48 GMT
< Expires: Tue, 26 Jan 2016 21:46:48 GMT
< Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Alternate-Protocol: 443:quic,p=1
< Alt-Svc: quic=":443"; ma=604800; v="30,29,28,27,26,25"
< Accept-Ranges: none
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
<
INVALID_REGISTRATION
* Connection #0 to host android.googleapis.com left intact
为什么我收到此错误?
答案 0 :(得分:0)
发件人ID是否为&#39;设备/应用令牌?
发件人ID是您在配置API项目时创建的唯一数值(以&#34;项目编号&#34;在Google Developers Console中提供)。在注册过程中使用发件人ID来标识允许向客户端应用程序发送消息的应用服务器。 (source)
to
的值应该是客户端应用的注册令牌。
您可以查看GCM文档的Simple Downstream Messaging页面以获取更多有用信息。