GCM 错误代码 [英] GCM Error Codes

查看:29
本文介绍了GCM 错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发送 GCM 推送通知的服务器应用程序.每次发送 1000 个收件人都会返回一条消息,告诉我每个注册 ID 的状态.有些会有错误代码.是否有来自 Google 的文档告诉我我应该如何处理这些代码以及所有可能的错误代码是什么?我的 Google foo 没有显示任何内容.

I've got a server app that sends GCM push notifications. Each send of 1000 recipients returns a message that tells me the status of each registration ID. Some will have error codes. Is there a document somewhere from Google that tells me how I'm expected to handle these codes and what all the possible error codes are? My Google foo isn't turning up anything.

推荐答案

你看起来不够努力.所有代码都在此处解释错误响应下进行了说明.

You didn't look hard enough. All the codes are explained here under Interpreting an error response.

我试图复制并粘贴它,以免它成为仅链接的答案,但格式有点不对:

I tried to copy and paste it in order for it not to be a link only answer, but the formatting is a bit off:

解释错误响应

以下是处理不同类型错误的建议尝试向设备发送消息时可能会发生这种情况:

Here are the recommendations for handling the different types of error that might occur when trying to send a message to a device:

缺少注册 ID检查请求是否包含注册 ID(在纯文本消息的 registration_id 参数中,或在JSON 中的 registration_ids 字段).当错误代码为 MissingRegistration 时发生.

Missing Registration ID Check that the request contains a registration ID (either in the registration_id parameter in a plain text message, or in the registration_ids field in JSON). Happens when error code is MissingRegistration.

无效的注册 ID检查传递给服务器的注册 ID 的格式.确保它与手机收到的注册 ID 匹配com.google.android.c2dm.intent.REGISTRATION 意图和你不截断它或添加额外的字符.当错误代码为 InvalidRegistration 时发生.

Invalid Registration ID Check the formatting of the registration ID that you pass to the server. Make sure it matches the registration ID the phone receives in the com.google.android.c2dm.intent.REGISTRATION intent and that you're not truncating it or adding additional characters. Happens when error code is InvalidRegistration.

发件人不匹配注册 ID 与特定的发件人组相关联.当应用程序注册 GCM 使用时,它必须指定哪些发件人是允许发送消息.确保您正在使用其中之一尝试向设备发送消息.如果您切换到不同的发件人,现有的注册 ID 将不起作用.出错时发生代码是 MismatchSenderId.

Mismatched Sender A registration ID is tied to a certain group of senders. When an application registers for GCM usage, it must specify which senders are allowed to send messages. Make sure you're using one of those when trying to send messages to the device. If you switch to a different sender, the existing registration IDs won't work. Happens when error code is MismatchSenderId.

未注册的设备在许多情况下,现有的注册 ID 可能不再有效,包括:

Unregistered Device An existing registration ID may cease to be valid in a number of scenarios, including:

  • 如果应用程序通过发出 com.google.android.c2dm.intent.UNREGISTER 意图手动取消注册.
  • 如果应用程序自动注销,如果用户卸载应用程序,这可能会发生(但不能保证).
  • 如果注册 ID 过期.Google 可能会决定刷新注册 ID.
  • 如果应用已更新但新版本没有配置为接收 com.google.android.c2dm.intent.RECEIVE 意图的广播接收器.

对于所有这些情况,您应该从第 3 方服务器中删除此注册 ID,并停止使用它来发送消息.当错误代码为 NotRegistered 时发生.

For all these cases, you should remove this registration ID from the 3rd-party server and stop using it to send messages. Happens when error code is NotRegistered.

消息太大消息中包含的有效负载数据的总大小不能超过 4096 字节.请注意,这包括键以及值.当错误代码为 MessageTooBig 时发生.

Message Too Big The total size of the payload data that is included in a message can't exceed 4096 bytes. Note that this includes both the size of the keys as well as the values. Happens when error code is MessageTooBig.

无效的数据键负载数据包含一个键(例如 from 或任何以 google 为前缀的值.)com.google.android.c2dm.intent.RECEIVE Intent,不能使用.笔记GCM 也使用了一些词(例如collapse_key)但是有效载荷中允许,在这种情况下,有效载荷值将是被 GCM 值覆盖.当错误代码为 InvalidDataKey 时发生.

Invalid Data Key The payload data contains a key (such as from or any value prefixed by google.) that is used internally by GCM in the com.google.android.c2dm.intent.RECEIVE Intent and cannot be used. Note that some words (such as collapse_key) are also used by GCM but are allowed in the payload, in which case the payload value will be overridden by the GCM value. Happens when the error code is InvalidDataKey.

无效生存时间生存时间字段的值必须是一个整数,表示 0 到 2,419,200(4 周)之间的持续时间(以秒为单位).当错误代码为 InvalidTtl 时发生.

Invalid Time To Live The value for the Time to Live field must be an integer representing a duration in seconds between 0 and 2,419,200 (4 weeks). Happens when error code is InvalidTtl.

身份验证错误您尝试用于发送邮件的发件人帐户无法通过身份验证.可能的原因有:

Authentication Error The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:

  • 授权标头缺失或语法无效.
  • 作为密钥发送的项目编号无效.
  • 密钥有效,但 GCM 服务已禁用.
  • 请求源自未在服务器密钥 IP 中列入白名单的服务器.

检查您在 Authorization 标头中发送的令牌是否是与您的项目关联的正确 API 密钥.你可以通过运行以下命令检查 API 密钥的有效性:

Check that the token you're sending inside the Authorization header is the correct API key associated with your project. You can check the validity of your API key by running the following command:

api_key=YOUR_API_KEY

api_key=YOUR_API_KEY

curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{"registration_ids":["ABC"]}"

curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{"registration_ids":["ABC"]}"

如果您收到 401 HTTP 状态代码,则您的 API 密钥无效.否则你应该看到这样的:

If you receive a 401 HTTP status code, your API key is not valid. Otherwise you should see something like this:

{"multicast_id":6782339717028231855,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

{"multicast_id":6782339717028231855,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

如果您想确认注册 ID 的有效性,可以通过将ABC"替换为注册 ID 来实现.当 HTTP 状态码为 401 时发生.

If you want to confirm the validity of a registration ID, you can do so by replacing "ABC" with the registration ID. Happens when the HTTP status code is 401.

超时服务器无法及时处理请求.您应该重试相同的请求,但您必须遵守以下要求:

Timeout The server couldn't process the request in time. You should retry the same request, but you MUST obey the following requirements:

如果 GCM 服务器的响应中包含 Retry-After 标头,请尊重它.在您的重试机制中实现指数退避.这意味着每次失败重试后延迟呈指数增长(例如如果您在第一次重试前等了一秒钟,请至少等待两秒钟下一秒之前,然后是 4 秒,依此类推).如果你是发送多条消息,每个消息独立延迟一个额外的随机数量以避免向所有人发出新的请求消息的同时.导致问题的发件人有被列入黑名单的风险.当 HTTP 状态码在 501 到 599 之间,或者结果数组中 JSON 对象的错误字段为不可用.

Honor the Retry-After header if it's included in the response from the GCM server. Implement exponential back-off in your retry mechanism. This means an exponentially increasing delay after each failed retry (e.g. if you waited one second before the first retry, wait at least two second before the next one, then 4 seconds and so on). If you're sending multiple messages, delay each one independently by an additional random amount to avoid issuing a new request for all messages at the same time. Senders that cause problems risk being blacklisted. Happens when the HTTP status code is between 501 and 599, or when the error field of a JSON object in the results array is Unavailable.

内部服务器错误服务器在尝试处理请求时遇到错误.您可以重试相同的请求(遵守要求超时部分中列出),但如果错误仍然存​​在,请在android-gcm组报告问题.当 HTTP 状态代码为 500 或结果数组中 JSON 对象的错误字段为 InternalServerError 时发生.

Internal Server Error The server encountered an error while trying to process the request. You could retry the same request (obeying the requirements listed in the Timeout section), but if the error persists, please report the problem in the android-gcm group. Happens when the HTTP status code is 500, or when the error field of a JSON object in the results array is InternalServerError.

包名称无效 消息发送到注册 ID,其包名称与请求中传递的值不匹配.当错误代码为 InvalidPackageName 时发生.

Invalid Package Name A message was addressed to a registration ID whose package name did not match the value passed in the request. Happens when error code is InvalidPackageName.

编辑(06/06/2015):

一个新的错误响应代码表已在此处发布.

A new error response codes table has been posted here.

新的错误响应:

超出设备消息速率 发送到特定设备的消息速率过高.减少发送到此设备的消息数量,不要立即重试发送到此设备.

Device Message Rate Exceeded The rate of messages to a particular device is too high. Reduce the number of messages sent to this device and do not immediately retry sending to this device.

Topics Message Rate Exceeded 发送给特定主题订阅者的消息速率过高.减少为此主题发送的消息数量,不要立即重试发送.

Topics Message Rate Exceeded The rate of messages to subscribers to a particular topic is too high. Reduce the number of messages sent for this topic, and do not immediately retry sending.

编辑(07/21/2019):

新的错误响应代码表已发布这里.

A new error response codes table has been posted here.

这篇关于GCM 错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆