Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

689
Vistas
Removing no longer valid FCM tokens from a database

I am sending notification to mobile device for which I have fcm tokens. On sending, I get a response that can for each fcm token have an error. I want to remove the invalid tokens that for sure will no longer work, but keep tokens that may have failed this time and could still work in the future.

I am using the node-gcm package.

What are the possible values for the error field in the response of each token. What checks on this value should I be making to only delete the permanently invalid tokens ?

    sender.send(gcmMessage, { registrationTokens: fcmTokens }, (error, response) => {
      if (error) {
        console.log(error);
      } else {
        const failedTokens = fcmTokens.filter((_, index) => response.results[index].error != null);
        if (failedTokens.length) {
          // If there are failed tokens, check these to know whether we should delete them.
          
          this.clearUserFcmTokens(userID, failedTokens);
        }
      }
    });
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The two most common error codes that indicate that the token should be removed are messaging/invalid-registration-token and messaging/registration-token-not-registered.

I recommend basing your logic on this code in the functions-samples repo.

over 4 years ago · Santiago Trujillo Denunciar

0

I got an answer from the repo itself.

They recommend checking if the error matches 'NotRegistered'.

I've modified the code to check 'NotRegistered' and 'InvalidRegistration':

    sender.send(gcmMessage, { registrationTokens: fcmTokens }, (error, response) => {
      if (error) {
        console.log(error);
      } else {
        const invalidTokenErrorKeys = ['NotRegistered', 'InvalidRegistration'];
        const failedTokens = fcmTokens.filter((_, index) => response.results[index].error != null && invalidTokenErrorKeys.includes(response.results[index].error));
        if (failedTokens.length) {
          this.clearUserFcmTokens(userID, failedTokens);
        }
      }
    });

The values of the error field match the HTTP Code column from this link:

https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes

examples: InvalidRegistration, NotRegistered, MessageTooBig, Unavailable etc.


Issue and response on the repo https://github.com/ToothlessGear/node-gcm/issues/360

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda