GCM用户通知:缺少"registration_ids"字段

Att*_* O. 12 android google-cloud-messaging

我们的项目已经列入白名单用于测试新的GCM 用户通知,允许分组的注册ID,然后到可用于将消息发送到该用户所拥有的所有设备的单一"通知键" API.

但是,当我发送这样的请求时:

POST /gcm/send
Authorization: key=…
Content-Type: application/json

{"notification_key": "…",
 "data": {…}
}
Run Code Online (Sandbox Code Playgroud)

我收到错误回复:

400 Bad Request

Missing "registration_ids" field
Run Code Online (Sandbox Code Playgroud)

使用registration_ids字段发送消息而不是notification_key修复问题(以及消息传递),但使用用户通知API的重点是使用notification_key而不是registration_ids.

从文档:

registration_ids:[...]请求必须包含收件人 - 这可以是注册ID,注册ID数组或notification_key.需要.

notification_key:将单个用户映射到与该用户关联的多个注册ID的字符串.这允许第三方服务器将单个消息发送到单个用户拥有的多个应用程序实例(通常在多个设备上).第三方服务器可以使用notification_key作为消息的目标,而不是单个注册ID(或注册ID数组).[…] 可选的.

上面的示例使用HTTP连接服务器https://android.googleapis.com.

到目前为止我试过:

  • 包括一个空数组registration_ids,没有帮助
  • notification_key在registration_ids字段中将值作为注册ID 发送,也不起作用
  • 将project_id标题设置为我们的项目编号(在创建时需要notification_key),仍然没有运气
  • 使用CCS(XMPP)代替HTTP与GCM API服务器通信,但遗憾的是IP在Google App Engine上被阻止
  • 包括notification_key和notification_key_name在请求中,并没有帮助

更新:根据此处的建议,我还尝试将有效负载发布到JSON请求有效负载中包含/gcm/notification的"operation": "send"属性.仍然没有帮助.现在我得到:

{"error":"Missing \"registration_ids\" field"}
Run Code Online (Sandbox Code Playgroud)

同样的事情,只有这次它被发送回JSON编码.

Jac*_*cki 10

文档有问题,您必须使用此请求:

curl -vvv -X POST --header "Content-Type: application/json" --header "project_id: <YOUR-PROJECT-ID>" --header "Authorization: key=<YOUR-PROJECT-SECRET-KEY>" --data @- "https://android.googleapis.com/gcm/send" << EOF
{ 
   "to": "<NOTIFICATION-ID>",
   "data": {},
}
EOF
Run Code Online (Sandbox Code Playgroud)

请参阅我的博客文章https://medium.com/appunite-edu-collection/d7df385b0ff4了解更多详情