mardi 30 mai 2017

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' => 'http://ift.tt/1TmHkUo',
    'server_group_url' => 'http://ift.tt/1mkLeNy',
    'timeout' => 30.0, // in second
],

];

Any help would be appreciated.



via Chebli Mohamed

2 commentaires:

  1. Ce commentaire a été supprimé par l'auteur.

    RépondreSupprimer
  2. if i want to send for IOS then what is the step for that and setup for .pem file in fcm.php ?

    RépondreSupprimer