Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
FCM Cloud messaging validate tokens

I have developed a web app with FCM Push Notifications.

It is sending and running fine except the following problem I have:

When someone subscribes, the token I get by the response, I save it into my mySQL database with some other user info I want.

When someone unsubscribes, after I get a successful response of unsubscribe, I delete the entry in my database.

BUT when someone unsubscribes by himself by not using my web application but by using the client (Chrome, Firefox etc) and by removing and not getting any more notifications from my web application, then I don't know that he did it in order to remove him from my database.

I don't see there is an FCM function which gives you all the active tokens in order to check and compare them with my database.

Is there any way to remove from my database all the inactive tokens?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One can validate these in batches of 500 registration ID each:

use Kreait\Firebase\Factory;
use Kreait\Firebase\Contract\Messaging;
use Kreait\Firebase\Exception\MessagingException;
use Kreait\Firebase\Exception\FirebaseException;

class SomeController {

    /** Constructor */
    public function __construct() {
        $factory = (new Factory)->withServiceAccount(getenv('GOOGLE_APPLICATION_CREDENTIALS'));
        $this->messaging = $factory->createMessaging();

    }

    /**
     * It validates device registration ID.
     *
     * @param string|string[] $token
     * @return array|bool|Exception|MessagingException|FirebaseException the validation results.
     */
    public function validate_fcm_token( string|array $token=[] ): bool|Exception|MessagingException|array|FirebaseException {
        if ($token == null|| is_array($token) && (sizeof($token) === 0 || sizeof($token) > 500)) {return false;}
        else if (is_string($token)) {$token = [ $token ];}
        try {
            return $this->messaging->validateRegistrationTokens($token);
        } catch ( MessagingException | FirebaseException $e ) {
            return $e;
        }
    }
}

This generally splits the input array into three output arrays, of which one is called invalid.

... also see the corresponding documentation.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda