【问题标题】:How to get failed token in firebase-php?如何在 firebase-php 中获取失败的令牌?
【发布时间】:2021-05-18 06:01:41
【问题描述】:

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

我已按照以下文档进行操作,并且运行良好:

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;
    }
}

【问题讨论】:

    标签: php firebase firebase-cloud-messaging


    【解决方案1】:

    你可以使用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?

    【讨论】:

      猜你喜欢
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      相关资源
      最近更新 更多