kreait / firebase-bundle

A Symfony Bundle for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
135 stars 25 forks source link

Requested entity was not found. In Parser.php line 95: The JWT string must have two dots #13

Closed k0v4back closed 5 years ago

k0v4back commented 5 years ago

Hello, When I try to send push notifications, I get errors: Requested entity was not found But I try to catch error, I have: In Parser.php line 95: The JWT string must have two dots

It is my code: (https://pastebin.com/xeZ4tbP9) `public function sendPush(string $pushTitle, string $pushBody, User $user){ $serviceAccount = ServiceAccount::fromJsonFile($this->dir); $firebase = (new Factory()) ->withServiceAccount($serviceAccount) ->create(); if(null !== $user->getDeviceTokens()){ foreach ($user->getDeviceTokens() as $token){

                try {
                    return $firebase->getAuth()->verifyIdToken($token->getToken());
                } catch (IssuedInTheFuture $e) {
                    exit;
                } catch (InvalidToken $e) {
                    echo $e->getMessage();
                    exit;
                }

            $messaging = $firebase->getMessaging();
            $message = CloudMessage::fromArray([
                'token' => $token->getToken(),
                'notification' => [
                    'title' => $pushTitle,
                    'body' => $pushBody
                ]
            ]);
            try{
                $messaging->send($message);
            }catch(\Kreait\Firebase\Exception\Messaging\NotFound $e){
                dump('Error');
            }
        }
    }
}`

I reshaped the token and the error was the same. The most interesting thing is that a few days ago this code worked, I did not change anything, but errors appeared.

What am I doing wrong?

jeromegamez commented 5 years ago

I don‘t know what role the parser plays here, and based on the Code and without a stack trace, I can’t determine the lines, but if the Firebase API returns „requested entity not found“, it means that the target device token is syntactically correct, but could not be found in the Firebase project‘s list of registered device tokens.

k0v4back commented 5 years ago

My device token was wrong, now all works brilliant. Thanks.

jeromegamez commented 5 years ago

Glad it turned out to be „just“ that 😅, thanks for letting me know!