kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.27k stars 431 forks source link

SendAll gets an error from Firebase - 501 - Operation is not implemented, or supported, or enabled. #929

Closed AlexTodessa closed 2 months ago

AlexTodessa commented 2 months ago

Describe the bug

While trying to send notifications using batches (doesn't differ betwee 1 or 500), started to get a message 501 Operation is not implemented, or supported, or enabled.

Tried to update to latest release, which was 8 hours ago, but problem still is there. Worked previously, so definitely a change on firebase side.

Sending messages one by one works without issues.

Installed packages

kreait/firebase-php           7.1.0   Firebase Admin SDK
kreait/firebase-tokens        4.1.0   A library to work with Firebase tokens

PHP version and extensions

php                    8.1.2    The PHP interpreter
php-64bit              8.1.2    The PHP interpreter, 64bit

Steps to reproduce the issue.

$tokens = [...];
foreach ($tokens as $token) {
    $message = CloudMessage::withTarget('token', $token)        
        ->withApnsConfig(
            ApnsConfig::new()->withDefaultSound()
        )        
        ->withNotification(Notification::create(
            'Test', 
            'testing testing 1 2 3'
        ));
    $messages[] = $message;
    $messaging->send($message);
}

$result = $messaging->sendAll($messages);
echo 'Successful sends: '.$result->successes()->count().PHP_EOL;
echo 'Failed sends: '.$result->failures()->count().PHP_EOL;

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

Error message/Stack trace

Successful sends: 0
Failed sends: 1
Operation is not implemented, or supported, or enabled.

Additional information

No response

AlexTodessa commented 2 months ago

sendMulticast gives same result

AlexTodessa commented 2 months ago

Important: The send methods described in this section were deprecated on June 21, 2023, and will be removed in June 2024. For protocol, instead use the standard HTTP v1 API send method, implementing your own batch send by iterating through the list of recipients and sending to each recipient's token. For Admin SDK methods, make sure to update to the next major version. See the Firebase FAQ for more information.

Guessing the only way now is to send one by one.

jeromegamez commented 2 months ago

You need to upgrade to a newer version, preferably ^7.15 - the updated FCM Batch handling was introduced in 7.5, I think.

jeromegamez commented 2 months ago

Ah, I just noticed in your original message that you already updated to the latest version. This is weird, it should definitely work. Can you confirm again that a composer show lists 7.15 as being installed? You might have to do a composer update --with-all-dependencies.

AlexTodessa commented 2 months ago

Upgrading to 7.15 fixed the issue :) indeed I upgraded to 7.1.0... Sorry for confusion, thank you!

Sikandarkhan commented 2 months ago

We are using 5.x. Trying to upgrade to 7.x. This change affects other packages .

Thank you for identifying the fix.