如何在 firebase-php 中获取失败的令牌?

How to get failed token in firebase-php?

我正在使用 firabase-php(https://github.com/kreait/firebase-php) 库将通知推送到带有 flutter 的多个设备。

我遵循了以下文档并且工作正常:

https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html#send-messages-to-multiple-devices-multicast

现在,我想从数据库中删除失败的令牌(如果有的话),但不确定如何获取它们。上面的文档展示了如何为每个请求获取消息。有没有办法获得失败的令牌?类似于 $failure->error()->getToken()?

if ($report->hasFailures()) {
    foreach ($report->failures()->getItems() as $failure) {
        echo $failure->error()->getMessage().PHP_EOL;
    }
}

您可以使用 the following methods:

// Registration tokens that are valid, but not 
// known to the current Firebase project
foreach ($report->unknownTokens() as $token) {
    echo $token.PHP_EOL;
}

// Invalid (malformed) tokens
foreach ($report->invalidTokens() as $token) {
    echo $token.PHP_EOL;
}

我不知何故错过了将其添加到文档中,但很快就会添加 finally managed to do so