FCM Messaging multicast send to tokens: how to determine which is unregistered?

1,784 views
Skip to first unread message

Вадим К

unread,
Nov 28, 2019, 10:55:40 AM11/28/19
to Firebase Google Group
Hi!

We are sending push notifications to list of tokens (batching by 100 tokens) using multicast.

Response contains a list of errors. How to determine which error related to which token? I want to clean up unregistered tokens, and i decided that errors in response has the same order as tokens in request, but when i started mark unregistered tokens, i find out that some of good tokens marked as unregistered.

What is a main approach to find out unregistered tokens when sending with multicast? 
Or Is there are any way to check that token is unregistered without sending push notification to it (maybe some ping or something like that)?

Thanks!

Kato Richardson

unread,
Nov 29, 2019, 12:34:17 PM11/29/19
to Firebase Google Group
Hello Вадим,

I think that's covered under send to multiple devices. Specifically, it has this example (you can visit the link for samples in other languages). Does that help?

admin.messaging().sendMulticast(message)
 
.then((response) => {
   
if (response.failureCount > 0) {
     
const failedTokens = [];
      response
.responses.forEach((resp, idx) => {
       
if (!resp.success) {
          failedTokens
.push(registrationTokens[idx]);
       
}
     
});
      console
.log('List of tokens that caused failures: ' + failedTokens);
   
}
 
});

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/3367fcc4-3a2e-464d-a75e-a7b3f7b6d461%40googlegroups.com.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Kato Richardson

unread,
Nov 29, 2019, 12:35:33 PM11/29/19
to Firebase Google Group
Sorry, I meant to include just a bit more context:

The idx in that example matches the order and contents of the array of tokens passed into the multicast call. 
const registrationTokens = [
 
'YOUR_REGISTRATION_TOKEN_1',
 
// …
 
'YOUR_REGISTRATION_TOKEN_N',
];

const message = {
  data
: {score: '850', time: '2:45'},
  tokens
: registrationTokens,
}
Reply all
Reply to author
Forward
0 new messages