对GCM服务器的HTTP Post请求总是返回“NotRegistered”

编程入门 行业动态 更新时间:2024-10-28 16:25:14
本文介绍了对GCM服务器的HTTP Post请求总是返回“NotRegistered”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

var options = {方法:'POST', uri:'android.googleapis/gcm/send ',标题:{'Content-Type':'application / json','Authorization':'key = VALUE'}, body: JSON.stringify({to:gcmId,data:{ message:message },})} request(options,function(error,response,body){ if(error)console.log(error); console.log(RESPONSE STATUS:+ response.statusCode) console.log(BODY:+ body); });

我将注册ID(gcmId)放在正确的位置吗?我似乎一直在收到: $ b $ {code $ {multicast_id:9098772304322316557,success:0,failure:1,canonical_ids :0,results:[{error:NotRegistered}]}

开始认为这是后端问题。 nofollow>官方文档 ...

如果它是NotRegistered,您应该从服务器数据库中删除注册ID因为应用程序是从设备上卸载的,或者客户端应用程序未配置为接收消息。

正确回答您的问题。

这里列出 GCM中的所有可能的错误代码,它再次表明以下关于 NotRegistered错误。

现有的注册令牌可能会在多种情况下停止有效,包括:

  • 如果客户端应用程序使用GCM注销。 如果客户端应用程序自动取消注册,如果用户卸载应用程序可能会发生这种情况。例如,在iOS上,如果APNS反馈服务报告APNS令牌无效。
  • 如果注册令牌到期(例如,Google可能决定刷新注册令牌或APNS令牌已过期的iOS设备)。
  • 如果客户端应用程序已更新,但新版本未配置为接收消息。 对于所有这些情况,从应用程序服务器中删除此注册令牌并停止使用它来发送消息。

var options = { method: 'POST', uri: 'android.googleapis/gcm/send', headers: { 'Content-Type': 'application/json', 'Authorization':'key=VALUE' }, body: JSON.stringify({ "to" : gcmId, "data" : { message: message }, }) } request(options, function (error, response, body) { if(error) console.log(error); console.log("RESPONSE STATUS: " + response.statusCode) console.log("BODY: " + body); });

Am I placing my registration id (gcmId) in the correct place? I seem to always be receiving:

{"multicast_id":9098772304322316557,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"}]}

Starting to think it's a backend problem.

解决方案

Quoting the official docs...

If it is NotRegistered, you should remove the registration ID from your server database because the application was uninstalled from the device, or the client app isn't configured to receive messages.

That appropriately answers your question.

Here the list of all possible error codein GCM which again says the following about NotRegistered error.

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

  • If the client app unregisters with GCM. If the client app is automatically unregistered, which can happen if the user uninstalls the application. For example, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
  • If the registration token expires (for example, Google might decide to refresh registration tokens, or the APNS token has expired for iOS devices).
  • If the client app is updated but the new version is not configured to receive messages. For all these cases, remove this registration token from the app server and stop using it to send messages.

更多推荐

对GCM服务器的HTTP Post请求总是返回“NotRegistered”

本文发布于:2023-10-09 16:36:43,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   GCM   HTTP   NotRegistered   Post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!