This repository contains a PHP script to send Firebase Cloud Messages (FCM) via the REST API. It includes both the generation of an OAuth2 access token using a Google service account key and the sending of FCM messages.
-
Clone the Repository
git clone https://github.com/tharushaudana/fcm-send-with-oauth2-php.git
-
Edit Service Account Key Path
In
access_token.php
, replace the placeholder with the path to your Google service account key JSON file:$creds = file_get_contents('path/to/your/service-account-key.json');
-
Edit FCM Data
In
index.php
, edit the FCM data to suit your needs. Change thevalidate_only
parameter totrue
if you only want to validate the request without sending a message:$firebase_data = [ 'validate_only' => false, 'message' => [ 'topic' => 'user_4', 'notification' => [ 'title' => 'test title', 'body' => 'test body', ], 'android' => [ 'collapse_key' => 'type_a', ], 'data' => [ 'test' => 'test value' ] ] ];
-
Load
index.php
Using a Web ServerEnsure you are running a web server, then load
index.php
to send the FCM message.
The screenshots below will help you create and download the Google service account key JSON for your Firebase project:
I hope this helps you implement the latest FCM send method via the REST API.