Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM_SENDER_ID or FCM_SERVER_KEY are invalid in laravel/brozot

I am new to FCM in laravel 5.2.

I am following this tutorial click here. But I am not able to send push notification. I have change the server and sender key in config/fcm.php but still it is throwing the error "FCM_SENDER_ID or FCM_SERVER_KEY are invalid".

Here I am using Api key as my server key and project number as sender Id.

        try {
    $optionBuilder = new OptionsBuilder();
    $optionBuilder->setTimeToLive(60*20);

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

    $dataBuilder = new PayloadDataBuilder();
    $dataBuilder->addData(['a_data' => 'my_data']);

    $option = $optionBuilder->build();
    $notification = $notificationBuilder->build();
    $data = $dataBuilder->build();

    $token = "...";

    $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
    print_r($downstreamResponse);die();

    $downstreamResponse->numberSuccess();
    $downstreamResponse->numberFailure();
    $downstreamResponse->numberModification();

    //return Array - you must remove all this tokens in your database
    $downstreamResponse->tokensToDelete(); 

    //return Array (key : oldToken, value : new token - you must change the token in your database )
    $downstreamResponse->tokensToModify(); 

    //return Array - you should try to resend the message to the tokens in the array
    $downstreamResponse->tokensToRetry();
}
    catch (\Exception $e) {
return $e->getMessage();

}

And my config/fcm.php

return [
'driver' => env('FCM_PROTOCOL', 'http'),
'log_enabled' => true,

'http' => [
    'server_key' => env('FCM_SERVER_KEY', '...'),
    'sender_id' => env('FCM_SENDER_ID', '....'),
    'server_send_url' => 'https://fcm.googleapis.com/fcm/send',
    'server_group_url' => 'https://android.googleapis.com/gcm/notification',
    'timeout' => 30.0, // in second
],

];

Any help would be appreciated.

like image 614
Mohammad Alfaz Avatar asked Oct 15 '25 14:10

Mohammad Alfaz


1 Answers

put those two parameters in the bottom of .env file just like that ...

FCM_SERVER_KEY=AAAAAAhDK2...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

and

FCM_SENDER_ID=358248592342

enter image description here

like image 57
Mohammed Atlassi Avatar answered Oct 18 '25 09:10

Mohammed Atlassi