brozot / Laravel-FCM

Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).
MIT License
888 stars 405 forks source link

Error sendTo FCM #79

Open Macario opened 6 years ago

Macario commented 6 years ago

Hello, sometimes my server got a error when it's sending message. Log below.

` production.ERROR: LaravelFCM\Response\Exceptions\InvalidRequestException: to in /home/producao/syncappapi/vendor/brozot/laravel-fcm/src/Response/BaseResponse.php:54 Stack trace:

0 /home/producao/syncappapi/vendor/brozot/laravel-fcm/src/Response/BaseResponse.php(32): LaravelFCM\Response\BaseResponse->isJsonResponse(Object(GuzzleHttp\Psr7\Response))

1 /home/producao/syncappapi/vendor/brozot/laravel-fcm/src/Response/DownstreamResponse.php(106): LaravelFCM\Response\BaseResponse->__construct(Object(GuzzleHttp\Psr7\Response))

2 /home/producao/syncappapi/vendor/brozot/laravel-fcm/src/Sender/FCMSender.php(57): LaravelFCM\Response\DownstreamResponse->__construct(Object(GuzzleHttp\Psr7\Response), Array)

3 /home/producao/syncappapi/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): LaravelFCM\Sender\FCMSender->sendTo(Array, NULL, Object(LaravelFCM\Message\PayloadNotification))

4 /home/producao/syncappapi/app/MessagePayload.php(32): Illuminate\Support\Facades\Facade::__callStatic('sendTo', Array)

5 /home/producao/syncappapi/app/Http/Controllers/EventController.php(374): App\MessagePayload->sendMessage('Sa\xC3\xADda', 'Andre Gurgel sa...', Array)

`

brozot commented 6 years ago

Hi Macario,

It seems that there are an error with the token are you sure that you provide a token to your request ?

Best Regards

darknlight111 commented 6 years ago

well, i have same problem too, in my local it's working well, but if i tried in production server, i got an error like @Macario

anyway @brozot this is my code :

$notificationBuilder = new PayloadNotificationBuilder('Welcome');
$notificationBuilder->setBody('Hello world')
                    ->setSound('default');

$notification = $notificationBuilder->build();

$topic = new Topics();
$topic->topic('testing');

$topicResponse = FCM::sendToTopic($topic, null, $notification, null);

$topicResponse->isSuccess();
$topicResponse->shouldRetry();
$topicResponse->error();

and i also inserted my firebase sender id and server key in my .env

how to fixed this case ?

agueroveraalvaro commented 5 years ago

well, i have same problem too, in my local it's working well, but if i tried in production server, i got an error like @Macario

anyway @brozot this is my code :

$notificationBuilder = new PayloadNotificationBuilder('Welcome');
$notificationBuilder->setBody('Hello world')
                  ->setSound('default');

$notification = $notificationBuilder->build();

$topic = new Topics();
$topic->topic('testing');

$topicResponse = FCM::sendToTopic($topic, null, $notification, null);

$topicResponse->isSuccess();
$topicResponse->shouldRetry();
$topicResponse->error();

and i also inserted my firebase sender id and server key in my .env

how to fixed this case ?

You should verify if there are tokens or if topic is not null, that worked for me!