对GCM服务器的HTTP Post请求总是返回“NotRegistered” [英] HTTP Post request to GCM server always returning "NotRegistered"

查看:186
本文介绍了对GCM服务器的HTTP Post请求总是返回“NotRegistered”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var options = 
{
方法:'POST',
uri:'https://android.googleapis.com/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: 'https://android.googleapis.com/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”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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