How to Use exponent-server-sdk-php to send push notifications to an app

Viewed 15

Please I need help in sending push notifications to anybody that installs my app on their android phone to get a push notification each time I create a post using PHP as the backend.

Here is my code for that:

$response = array();
require_once __DIR__.'/exponent-server-sdk-php/vendor/autoload.php';


        $channelName = 'video_alert';
        $recipient =  'ExponentPushToken[AAAAnrlyESE:APA91bHYeOkFi5MlUB9eitKn1yEuReJ1dNrRSnlMob0lcBLAjoanDaAIposGTBWQD164CGMV8F0hriJtsXuaFPdoKxEpjtrnXshoxlZQmxdlrCjP_F5TyRToNGP43YqwahCd6XYhKvwX]';
        
        // You can quickly bootup an expo instance
        $expo = \ExponentPhpSDK\Expo::normalSetup();
        
        // Subscribe the recipient to the server
        $expo->subscribe($channelName, $recipient);
        
        // Unsubscribe the recipient from the server
        $expo->unSubscribe($channelName, $recipient);
        
        // Build the notification data
        $notification = ['title' => 'Watch Movies', 'body' => 'Catch new latest movie ('.$movie_title.') on DooBuxx Movies today!', 'data' => json_encode(array('notification_type' => 'service_requested'))];
        try {
        // Notify an interest with a notification
        $expo->notify([$channelName], $notification);
        }  catch (ExpoException $e) {
            $response["message"] = $e->getMessage();
         }

For the following part:

$channelName = 'video_alert';
        $recipient =  'ExponentPushToken[Server key]'; // I Inserted the server key i got from my firebase dasboard here. The package name is ok

Is the server key the right thing? or what? This is where I think I'm not doing it right. But I don't know what else to put there.

As you can see, I'm using the exponent-server-sdk-php that I cloned from GitHub to send the push notification but it's not sending anything after posting to the server.

Is there anything I'm doing wrong here? I have also checked the error log, but there is no erro in there.

When I posted the first time, a token file was created though but no notification was sent to the android phones that have the app installed.

I have configured my firebase credentials for the react native project I'm building after following the instructions from the expo website here but all to no avail.

I know I'm not doing something all right here but can't seem to figure it out yet. Please help.

0 Answers
Related