samedi 27 février 2016

Laravel Push Notifications doesn't work on server, receiving null response

I am using Laravel 5.1 with davibennun/laravel-push-notification library in order to send push notifications.

With this library I am doing the following:

 // Makes a DeviceCollection with my fetched devices
 // $androidTokens is an array of Device objects with my tokens
 $deviceCollection = $this->pushNotificationManager
          ->DeviceCollection($androidTokens);

 // Sends the push notification message
 $collection = $this->pushNotificationManager->app('appNameAndroid')
        ->to($deviceCollection)
        ->send($message);

 // Logs the response status
 foreach ($collection->pushManager as $push) {
        $response = $push->getAdapter()->getResponse();
        Log::info('Push notification response:', [
            'response' => $response,
        ]);
    }

I already configured my push notifications credentials on the generated push-notifications.php file with the following:

 'appNameAndroid' => array(
    'environment' => env('GCM_ENVIRONMENT'),
    'apiKey'      => env('GOOGLE_API_SERVER_KEY'),
    'service'     =>'gcm'
)

And configured everything on my google developer console to enable Google Cloud Messaging with specified keys.

I already tried on my local Homestead machine with my credentials, and it is able to send the push notification successfully. However, when i tried the same in my production server, push notification is not sent and my application logs the following:

 production.INFO: Push notification response: {"response":null}

I don't really have a clue as to why it is not working, as on my local machine push sends successfully and logs the following response:

 local.INFO: Push notification response: {"response":"[object] (ZendService\\Google\\Gcm\\Response: {})"}

Note: they have the exact same configuration (server key, GCM environment) and I am copying my device tokens from my production server to my local homestead machine to test notifications.

So it seems there's some problem communicating with google services from the server.

I have already checked for many issues like:

  • Checking if my api key configuration on the google console is blocking my production's server ip address (already removed ip filtering and it doesn't work)
  • Checking if my generated server key is invalid, which i used the method described here: http://ift.tt/1T0ULL8 under Checking the validity of an API key which i got the expected success response.

I have looked for hours to a solution to this error, but i couldn't find anything related on the subject so i already ran out of ideas.

Just in case it helps, i'm using homestead version 0.4.0 on a VirtualBox provider, and my production server is hosted on Digital Ocean and it's being managed by Laravel Forge (dunno if it's some sort of port configuration issue or if there is some extra process involved with this technologies).

Any ideas as to why this is not working would be really appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire