gpt4 book ai didi

android - GCM 用户通知 : Missing "registration_ids" field

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:34 26 4
gpt4 key购买 nike

我们的项目已被列入白名单以测试新的 GCM User Notifications允许将注册 ID 分组为单个“通知 key ”的 API,然后可以使用该 key 向用户拥有的所有设备发送消息。

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

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

{"notification_key": "…",
"data": {…}
}

我收到错误响应:

400 Bad Request

Missing "registration_ids" field

使用 registration_ids 字段而不是 notification_key 发送消息解决了这个问题(并且消息被传递),但是使用用户通知 API 的全部意义在于使用 notification_key 而不是 registration_ids

来自documentation :

registration_ids: […] A request must include a recipient—this can be either a registration ID, an array of registration IDs, or a notification_key. Required.

notification_key: A string that maps a single user to multiple registration IDs associated with that user. This allows a 3rd-party server to send a single message to multiple app instances (typically on multiple devices) owned by a single user. A 3rd-party server can use notification_key as the target for a message instead of an individual registration ID (or array of registration IDs). […] Optional.

以上示例使用位于 https://android.googleapis.com 的 HTTP 连接服务器。

到目前为止我试过:

  • registration_ids 包含一个空数组,没有帮助
  • 发送 notification_key 值作为 registration_ids 字段中的注册 ID 也不起作用
  • project_id header 设置为我们的项目编号(根据创建 notification_key 的要求),仍然没有成功
  • 使用 CCS (XMPP) 而不是 HTTP 与 GCM API 服务器通信,但不幸的是 the IP is blocked on Google App Engine
  • 在请求中同时包含 notification_keynotification_key_name 没有帮助

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

{"error":"Missing \"registration_ids\" field"}

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

最佳答案

文档有问题,你必须使用这个请求:

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

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

关于android - GCM 用户通知 : Missing "registration_ids" field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19720767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com