Get Google FCM oAuth Token programmatically with PHP

Job ID: 37922704

Budget: $10 – $30 USD

I have a php server that is a backend of an andoid/iphone app.
The app registers itself to Firebase, and I would like to send push messages he devices via FCM REST API.

It is working well if I get the oAuth Token myself and add hard-coded to the POST message.

The goal of this project is to provide me with a PHP code that gets the oAuth Token programmatically, as in:
https://github.com/googleapis/google-api-php-client

I expect a working code something like this:
// START
$client = new Google_Client();

// WHATEVER .....

// Authenticate and get the access token
if ($client->isAccessTokenExpired()) {
$client->refreshTokenWithAssertion();
}

$accessToken = $client->getAccessToken();

// Access token to use with FCM REST API
$token = $accessToken['access_token'];

echo "Access Token for FCM: " . $token . "\n";
// END

You would need to provide me all files needed for it to run (dont tell me to install anything - just send me all files).

I have google-services.json file if needed.
Related categories: PHP Google Firebase