I can send notifications via Firebase Messaging using the CURL request below. I'm currently using the OAuth 2.0 Playground to obtain access tokens. I need to implement a PHP script to do this. How to generate access token programmatically in PHP?
curl -X POST -k -H 'Authorization: Bearer access_token_goes_here' -H 'Content-Type: application/json' -i 'https://fcm.googleapis.com/v1/projects/projectId/messages:send' --data '{ "message":{ "topic" : "newTopic", "notification" : { "body" : "This is a Firebase Cloud Messaging Topic Message!", "title" : "FCM Message" } } }
I found a lot of solutions, but they all require a lot of libraries and dependencies.
I build my own solution with no additional dependencies. This is the api for getting OAuth2 tokens: https://developers.google.com/identity/protocols/oauth2/service-account#httprest
The first step is to create a JWT (Json Web Token). Using this JWT, a bearer token can be requested.
$response
Contains the bearer token. You should store this token for use by other requests and request a new bearer token when it is about to expire. The maximum lifetime of this bearer token is 1 hour.